-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Manually created CORS-enabled Proxy API leads to different config in SAM #807
Comments
I think the API Gateway Console creates the Model for you. You can explicitly create the model using CloudFormation if you need to, though I think you will then need to manually create your OPTIONS method to use that model. |
Thanks for the response @brettstack. In addition to this, I found that the Response Headers are missing in the Gateway Responses section too: Manual: Via SAM: That looks more serious? |
any info on this? I'm also unable to set cors on sam created API. still leads to missing headers and I'm unable to consume my sam crated API in SPA due to CORS. |
When you say that the headers are missing, do you mean in the preflight response or in the actual application response? SAM (really, API Gateway) cannot add CORS headers to the responses returned by the application. The CORS settings apply to preflight responses – that is, the responses to the |
yep true - also worth mentioning is the fact that default authorizer is also applied to the OPTIONS requests... so I ended up with two things (making it work):
|
Hi @lukpep I have returned CORS headers into responses directly in a functions code, but after the deploy with a sam template, the cors is still not working. Is it just me? or have you got it fixed? Could you please share more information. Thanks! |
I'm seeing the same thing as @didopop3. I have the following in the Api:
Cors:
AllowOrigin: "'*'"
AllowMethods: "'*'"
AllowHeaders: "'*'" and I'm explicitly returning CORS headers in my function code: return {
body: 'Unprocessable',
statusCode: '204',
headers: {
'Access-Control-Allow-Origin': headers.Origin,
'Content-Type': 'text/plain',
}
} When running locally, CORS headers are included in responses, but when running in production, |
Any update on this, If we upload our SAM Application will not work because of CORS, but if via de console you recreate the API's then they work, this is not maintainable since the SAM its a yaml you could maintain with PR's and code change management, if its only via the console, once you re-upload the SAM for whatever reason, all the configuration made on the console gets lost. |
Description:
When deploying an implicit API with SAM and then doing what I take to be the same steps in API Gateway in the AWS Console, I end up with a different configuration. To be sure, I'm not sure if this is a support request or a behaviour that needs better documentation or a bug.
Steps to reproduce the issue:
1/ In Console, create a Proxy resource. Steps: Go to API Gateway => Create API => (Name=MyAPI, Endpoint Type=Edge Optimized). Then: Actions => Create Resource => (Configure as Proxy resource, leave Enable API Gateway CORS UNchecked) => Create Resource. Then: Lambda Function=Some Lambda Function. Then: Save. Then: Select the /{proxy+} resource => Actions => Enable CORS => (Gateway Responses for MyAPI API=Default 4XX,Default 5XX) => Enable CORS and replace existing CORS headers.
2/ In a SAM template:
Observed result:
For the manually create API I see in the Method Response "Models: application/json => Empty" as shown here:
For the SAM-created API I don't see the Models:
Expected result:
I expected both these approaches to result in the same config, and if not, I expected to be able to somehow use SAM to generate the same config I generated manually.
Additional info:
This may be related to #640
The text was updated successfully, but these errors were encountered: