RFC: Simplifying CORS #1918
jeromevdl
started this conversation in
RFCs (Request for Comments)
Replies: 1 comment
-
This is one of the most common issues people face. It will greatly improve DX. Some comments:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Key information
Summary
When working with API Gateway + Lambda, developers need to handle CORS Headers properly, to make sure their API can be called by a web frontend and to avoid cross origin requests to be blocked. This module would simplify adding CORS headers in the response of their Lambda function when used with an API Gateway Proxy.
Motivation
Adding CORS in the response headers is either forgotten (and nothing works as expected), either boring (a lot of boilerplate code, with very specific syntax). With the wish to simplify developer life, Lambda Powertools could bring something.
Proposal
@CrossOrigin
RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent>
, the annotation will automatically add the headersAccess-Control-Expose-Headers
,Access-Control-Allow-Origin
,Access-Control-Allow-Methods
,Access-Control-Allow-Credentials
,Access-Control-Max-Age
to the response object.Authorization, *
(*)Access-Control-Allow-Headers
header*
Access-Control-Expose-Headers
header*
Access-Control-Allow-Origin
header*
Access-Control-Allow-Methods
headertrue
Access-Control-Allow-Credentials
header29
Access-Control-Max-Age
headerExample:
Authorization, *
(*)Access-Control-Allow-Headers
header*
Access-Control-Expose-Headers
header*
Access-Control-Allow-Origin
header*
Access-Control-Allow-Methods
headertrue
Access-Control-Allow-Credentials
header29
Access-Control-Max-Age
headerDrawbacks
This new module can bring a few additional kb to the lambda package size. It does not use any dependency which is not already in the core module.
Rationale and alternatives
Unresolved questions
N/A
Beta Was this translation helpful? Give feedback.
All reactions