Unable to set CORS headers when there is a unhandled Lambda exception #1027
Labels
area/local/start-api
sam local start-api command
maintainer/need-response
type/feature
Feature request
Description
If I create a
AWS::Serverless::Function
that is triggered by an API Gateway event, and an unhandled exception occurs in my code, the error message sent back to the user is a 502 Bad Gateway error from the API Gateway. Unfortunately this error message doesn't have any CORS headers by default, so if the webpage that called the endpoint is not on the same domain as the API Gateway, a CORS error will also be triggered in the browser.Previously when I used the serverless framework I would address this issue by creating a CloudFormation resource to set the
DEFAULT_5XX
Gateway Response for that particular API. For some reason doing so doesn't seem to have any effect for APIs created using sam-cli.Steps to reproduce
Create a
AWS::Serverless::Function
with an event of typeApi
and throw an exception when the function is called.Add the following resource to template.yaml
Observed result
No CORS headers are present on the 502 response from the API endpoint
Expected result
CORS headers should be present on the 502 response from the API endpoint
I am not sure if this has something to do with the fact that sam-cli uses embedded swagger templates when defining the RestApi, but that would be my first guess. I am just looking for a way to address the issue, even if it is another workaround
The text was updated successfully, but these errors were encountered: