-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Switch internals to use Lambda proxy integration #240
Conversation
This change replaces the VTL related configuration with AWS Lambda proxy integration. See: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html For the most part this is a transparent change to the user, but with a couple of additional benefits: * Users can return customer response bodies, headers, and status codes * Slightly faster deployments because we no longer have to configure error regex's for each of the built-in-regex types. Internally, this simplifies things. We don't have to manage VTL for doing the full passthrough. This approach was taken only because Lambda proxy integration didn't exist yet. Now that it does, switching over makes sense. In terms of implementation, the only notable thing was that I had to move some of the processing into the chalice handler that was previously handled by API gateway. This includes: * JSON serialization. The response body we need to return from the lambda function must now be a string. Previously we were returning any python type and relying on lambda to serialize the python data structure for now. Now this happens in the chalice handler. This also means we can expand our serialization support for JSON that was difficult to do previously (for example automatically serializing datetime objects). * CORS support for any view function written in python. We could leverage the integration response to inject the CORS headers needed. This now happens in the chalice handler. The OPTIONS request is still driven entirely by API gateway so we're still able to bypass Lambda for OPTIONS. And finally, there are a couple of user facing changes (I'll add these to the documentation/ugprade notes): * Uncaught exceptions are now `InternalServerError` instead of `ChaliceViewError` when not running debug mode. * In debug mode, the original traceback (as a string) is sent as the entire request body. Previously, we were relying on Lambda to serialize the stack trace into a JSON object, where the traceback was a list of lines. I think this results in an easier to debug stacktrace.
Also removed the section on content_types. It's no longer needed.
Codecov Report
@@ Coverage Diff @@
## master #240 +/- ##
==========================================
- Coverage 79.2% 79.17% -0.03%
==========================================
Files 13 13
Lines 1510 1508 -2
Branches 198 197 -1
==========================================
- Hits 1196 1194 -2
+ Misses 259 257 -2
- Partials 55 57 +2
Continue to review full report at Codecov.
|
Also cleaned up some of the formatting of the existing deploy code.
One small change I'm going to make. With the proxy integration we don't provide the requestTemplates for content-types which means that you don't get the 415 response for undeclared content-types. To support this I'll need to add this behavior into the chalice lambda handler. Might be worth dropping support for this in a future release but for now I'll keep those compatible. |
This use to be handled by API gateway, but now that we're using AWS_PROXY this is now handled by the chalice view function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢 The added functionality seems really useful.
I also updated the README to reflect those latest changes.
We're preserving this behavior for the time being.
This change replaces the VTL related configuration with AWS
Lambda proxy integration.
See: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html
For the most part this is a transparent change to the user, but with a
couple of additional benefits:
error regex's for each of the built-in-regex types.
Internally, this simplifies things. We don't have to manage VTL for
doing the full passthrough. This approach was taken only because Lambda
proxy integration didn't exist yet. Now that it does, switching over
makes sense.
In terms of implementation, the only notable thing was that I had to
move some of the processing into the chalice handler that was previously
handled by API gateway. This includes:
lambda function must now be a string. Previously we were returning
any python type and relying on lambda to serialize the python data
structure for now. Now this happens in the chalice handler. This
also means we can expand our serialization support for JSON that was
difficult to do previously (for example automatically serializing
datetime objects).
leverage the integration response to inject the CORS headers needed.
This now happens in the chalice handler. The OPTIONS request is
still driven entirely by API gateway so we're still able to bypass
Lambda for OPTIONS.
And finally, there are a couple of user facing changes (I'll add these
to the documentation/ugprade notes):
InternalServerError
instead ofChaliceViewError
when not running debug mode.the entire request body. Previously, we were relying on Lambda
to serialize the stack trace into a JSON object, where the traceback
was a list of lines. I think this results in an easier to debug
stacktrace.
Wanted to get this out for any early feedback, but there's a couple of pending things pending I need to do:
claims
key. This was originally a top level key,and I believe this is now moved into the request context. Need to double check.