Убедитесь, что у вас есть метод options
в вашем пути в API Gateway:
Api:
Type: AWS::ApiGateway::RestApi
Properties:
Name: "my-api"
Body:
swagger: "2.0"
info:
version: "2018-03-20T13:41:34Z"
basePath: "/"
schemes:
- "https"
paths:
/my-path:
options:
responses:
"200":
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'GET,POST,PUT,DELETE,OPTIONS'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,x-api-key,x-amz-security-token,Auth'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\":200}"
passthroughBehavior: when_no_match
type: mock
post:
...
В вашей лямбде вы можете установить заголовок следующим образом:
exports.handler = async event => {
...
return {
isBase64Encoded: false,
statusCode: 200,
headers: {
'Access-Control-Expose-Headers': 'Content-Type,...',
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}
}