-
Notifications
You must be signed in to change notification settings - Fork 429
APIGatewayEventRequestContext have confusing or wrong behavior on "get" and "raw_event" properties #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ricardoinacio yes this should help fix this: @property
def request_context(self) -> APIGatewayEventRequestContext:
return APIGatewayEventRequestContext(self._data["requestContext"]) Could you do me a favor and include a sample event with |
part of the confusion of However sometimes it helps for the items inside of a data class to be getting a sub node within the main event dict, so then Either way, i can fix this behavior, but i just want to be sure we have a good standard going ahead (and in this case an example that include |
@ricardoinacio i added the missing field: #373 |
@ricardoinacio this will be out in our next release in April, hopefully in two weeks time if we manage to include the new event_handler utility on time. I'll ping back here once it's out. Thank you again for raising this so we can iron the edges out! |
@michaelbrewer @heitorlessa Thank you, guys! I think the solution is great, and should help. Also, maybe Here is the base event I use for local testing. {
"body": null,
"resource": "/resources",
"path": "/resources",
"httpMethod": "GET",
"isBase64Encoded": false,
"queryStringParameters": {
"foo": "bar"
},
"multiValueQueryStringParameters": {
"foo": [
"bar"
]
},
"pathParameters": null,
"stageVariables": null,
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8",
"Cache-Control": "max-age=0",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Host": "1234567890.execute-api.us-east-1.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Custom User Agent String",
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"multiValueHeaders": {
"Accept": [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
],
"Accept-Encoding": [
"gzip, deflate, sdch"
],
"Accept-Language": [
"en-US,en;q=0.8"
],
"Cache-Control": [
"max-age=0"
],
"CloudFront-Forwarded-Proto": [
"https"
],
"CloudFront-Is-Desktop-Viewer": [
"true"
],
"CloudFront-Is-Mobile-Viewer": [
"false"
],
"CloudFront-Is-SmartTV-Viewer": [
"false"
],
"CloudFront-Is-Tablet-Viewer": [
"false"
],
"CloudFront-Viewer-Country": [
"US"
],
"Host": [
"0123456789.execute-api.us-east-1.amazonaws.com"
],
"Upgrade-Insecure-Requests": [
"1"
],
"User-Agent": [
"Custom User Agent String"
],
"Via": [
"1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)"
],
"X-Amz-Cf-Id": [
"cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA=="
],
"X-Forwarded-For": [
"127.0.0.1, 127.0.0.2"
],
"X-Forwarded-Port": [
"443"
],
"X-Forwarded-Proto": [
"https"
]
},
"requestContext": {
"operationName": "list-resources",
"accountId": "123456789012",
"resourceId": "123456",
"stage": "dev",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"requestTime": "09/Apr/2015:12:34:56 +0000",
"requestTimeEpoch": 1428582896000,
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"accessKey": null,
"sourceIp": "127.0.0.1",
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "Custom User Agent String",
"user": null
},
"path": "/dev/resources",
"resourcePath": "/resources",
"httpMethod": "GET",
"apiId": "1234567890",
"protocol": "HTTP/1.1"
}
} |
@ricardoinacio To be honest, the
|
Thank you guys, and great job! |
I needed access to key
operationName
fromrequestContext
fromAPIGatewayProxyEvent
. The problem is thatAPIGatewayEventRequestContext
doesn't have this property, forcing me to use either theget
accessor or theraw_event
property fallback. And the real problem is that when you use any of these to access the original data, but from theAPIGatewayEventRequestContext
, it does in fact give you the rootAPIGatewayProxyEvent
event data. So I had lots of confusing behavior and lost time with debugging.Eg.
Expected Behavior
I expected both
apigw_event.request_context.get('operationName')
andprint(apigw_event.request_context.raw_event['operationName'])
to return"some-openapi-operation-name"
.Current Behavior
Both give errors because they access root
self._data: DictWrapper
instead ofself._data['requestContext']
.Environment
The text was updated successfully, but these errors were encountered: