当API Gateway代理到S3的PUT请求时遇到CORS问题,可以通过以下步骤解决:
{
"swagger": "2.0",
"info": {
"title": "API Gateway to S3 CORS Example",
"version": "1.0"
},
"paths": {
"/s3proxy": {
"put": {
"responses": {
"200": {
"description": "PUT request successful"
}
},
"x-amazon-apigateway-integration": {
"type": "aws_proxy",
"httpMethod": "PUT",
"uri": "arn:aws:apigateway:us-east-1:s3:path/{bucket}/{key}",
"credentials": "arn:aws:iam::123456789012:role/MyS3Role",
"requestParameters": {
"integration.request.path.bucket": "method.request.path.bucket",
"integration.request.path.key": "method.request.path.key"
},
"responses": {
"default": {
"statusCode": "200"
}
}
},
"x-amazon-apigateway-cors": {
"allowOrigins": ["*"],
"allowMethods": ["PUT"],
"allowHeaders": ["Content-Type"],
"exposeHeaders": []
},
"parameters": [
{
"name": "bucket",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "key",
"in": "path",
"required": true,
"type": "string"
}
]
}
}
}
}
*
PUT
Content-Type
通过以上步骤,API Gateway代理到S3的PUT请求应该不再遇到CORS问题。