Open CraigStuntzWillowTree opened 2 years ago
Thanks for reporting this to us! I will try to reproduce this to confirm the behaviour, then we can get back to this to discuss the following steps!
Oddly, for me this was ignored (no updates in the actual API Gateway CORS configuration, and no errors during build or deploy):
CorsConfiguration:
AllowCredentials: true
AllowHeaders:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- X-Amzn-Trace-Id
AllowMethods:
- OPTIONS
- GET
- POST
- PUT
AllowOrigins: !FindInMap [StageMap, !Ref Stage, AllowedOrigins]
but this worked (the actual API Gateway CORS configuration was updated):
CorsConfiguration:
AllowCredentials: false
AllowHeaders:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- X-Amzn-Trace-Id
AllowMethods:
- OPTIONS
- GET
- POST
- PUT
AllowOrigins:
- "*"
Description:
CORS doesn't work in
sam
for simple requests when usingAWS::Serverless::HttpApi
. It does work on preflighted requests, and it also works on "real" AWS.Steps to reproduce:
(I couldn't get this to work at all if I put the
CorsConfiguration
in theAWS::Serverless::HttpApi
element instead of inGlobals
, despite your configurator saying it should work in either place. That's an issue for another ticket.)We are running this with
npm run start:dev
where:Observed result:
(Note no
Access-Control-Allow-Origin
header.)Expected result:
Here it is running on "real" AWS (we deploy with terraform, not
sam
, so I believe this is close to what SAM might deploy, but essentially I've just configured CORS on the API Gateway)(Note
Access-Control-Allow-Origin
header is present.)A preflight request against
sam
also works:Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
:SAM CLI, version 1.43.0
us-west-2
is working correctly