I'm trying to enable CORS in my AWS SAM app. Here is the snippet from my template.yaml:
Globals:
Api:
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Auth:
Authorizers:
MyCognitoAuthorizer: ...
getByIdFunc:
Type: AWS::Serverless::Function
Properties:
Handler: src/handler.handle
Events:
ApiEvent:
Type: Api
Properties:
Path: /{id}
Method: GET
RestApiId: !Ref MyApi
Run Code Online (Sandbox Code Playgroud)
根据此Using CORS with AWS SAM和https://github.com/aws/serverless-application-model/issues/373,cors配置应该可以工作,但不幸的是API响应上没有设置标头,如下所示。
< HTTP/2 200
< content-type: application/json
< content-length: 770
< date: Tue, 13 Apr 2021 …Run Code Online (Sandbox Code Playgroud) amazon-web-services cors aws-api-gateway aws-sam infrastructure-as-code