I'm using AWS Serverless
for building a small site with around 15 Lambda functions.
My Cloudformation stack is completely built using SAM
.
I'm NOT using Lambda proxy integration.
The Api section in the SAM
yaml template config looks like this:
AppApi:
Type: AWS::Serverless::Api
Properties:
Cors:
AllowMethods: "'*'"
AllowHeaders: "'Content-Type'"
AllowOrigin: "'*'"
...........More Stuff..........
When I deploy this SAM
yaml template, I see that my ApiGateway created the OPTIONS verb for all methods and when I shoot a request with the OPTIONS verb, I do see the CORS
headers correctly.
The problem is that the other verbs (e.g. POST) don't add those headers to their response as the OPTIONS request did and when I run my api from the browser I get the cross origin policy error in my console.
So my current workaround was to add the CORS header using integrated responses to specific status codes, but I cannot and dont want to handle that for 15 methods and I want to support all response status codes (e.g. 4xx\5xx etc.).
My questions:
- Am I doing anything wrong here or is this a
SAM
bug? - If this is a bug, is there any workaround other from adding the headers using integrated responses (or from my code)?
- Is there a way I can add headers "globally" from an Api Gateway? Or support some kind of global integrated responses?