Хорошо, я нахожу это.
Мы должны добавить лямбда-функцию в template.yaml:
resLambdaLocalCorsStub:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs6.10
FunctionName: corsOptions
CodeUri: corsOptions/
Timeout: 30
Events:
loginOptions: # This block must be repeated for each endpoint that needs CORS support in SAM Local
Type: Api
Properties:
RestApiId: !Ref ApiGatewayRestApi
Path: /project/{id}
Method: OPTIONS
и это в apigateway
options:
x-amazon-apigateway-integration:
type: mock
requestTemplates:
application/json: '{ "statusCode" : 200 }'
httpMethod: OPTIONS
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Origin: "'*'"
responseTemplates:
application/json: '{}'
responses:
'200':
headers:
Access-Control-Allow-Headers:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Origin:
type: string
И чтобы закончить, создайте лямбду с:
"use strict";
// ***** This handler is used only in local development, for mocking the OPTIONS responses
// ***** This enables API Tests to pass CORS tests when running locally
exports.handler = (event, context, callback) => {
callback(null, {
statusCode: 200,
headers: {
"Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key",
"Access-Control-Allow-Methods": "POST, GET, PUT, DELETE",
"Access-Control-Allow-Origin": "*"
},
body: ""
});
};