-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bug: CORS Support in start-api #4161
Comments
@sravimohan According to API Gateway docs, the Lambda is responsible for adding the See https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html SAM only support proxy integrations, both in the cli and in the Spec. Am I miss understanding something? |
Hi @jfuss, Thank you for looking into this. This is a non-proxy integration as you can see from the template above. The exact same template deployed to AWS automatically adds 'access-control-allow-origin' to the response. whereas the running it locally with 'sam local start-api' does not.
I am not clear what you mean by 'SAM only support proxy integrations'? The above template was generated through sam init and deployed to AWS using 'sam deploy'. It works as expected when deployed to AWS. The issue is running locally for development. |
@sravimohan The odd thing to me is API Gateway has one thing documented (what we are doing locally) but has different behavior. I can't tell if this is something in the docs that needs updated or there is an issue with API Gateway.
As a note: You are using proxy integrations, given the last comment you made. |
@sravimohan Actually, I was looking at the wrong docs 🤦♂️. You are using Http Api not Rest. So these are the right docs: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html which explains the difference. Are you willing to submit a PR to patch this? |
@jfuss, I am not very familiar with python. So may not be able get PR ready. I can give it a go if nobody else is keen. |
Thanks @sravimohan +1, im having the same issue using |
I am facing a similar issue and this is really painfull. A workaround which I am using it cors middleware in middly Hope this is helpful for people who are stuck. |
hi @sravimohan @jfuss @moelasmar I might be able to work on this. A few pointers into where should I look at could make this a bit faster. |
Hi there @sleepwithcoffee thanks for the interest! https://github.com/aws/aws-sam-cli/blob/develop/samcli/commands/local/start_api/cli.py#L193 is the starting point of a
|
We had to revert the fixing PR as it causes some regressions. |
Patch is released in v1.96.0. Closing |
"sam local start-api" does not return cors headers in the lambda responses.
This issue was marked as fixed and closed in #323. but seems to have regressed and is no longer working any more.
The options request correctly returns the CORS headers. But the lambda response does not include "access-control-allow-origin" header.
The only workaround is to also manually include "access-control-allow-origin" header in the lambda responses.
Pl. note its works fine when deployed without any workaround.
minimal repo for reproducing issue
https://github.com/sravimohan/bug-aws-sam-cli-4161
template.yml
function
The text was updated successfully, but these errors were encountered: