在API Gateway的CORS设置中添加Access-Control-Allow-Origin头信息。在Lambda函数中添加一个返回头部信息的代码,以便API Gateway具有正确的CORS配置:
exports.handler = function(event, context, callback) {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token",
"Access-Control-Allow-Credentials" : true ,
"Content-Type": "application/json"
},
body: JSON.stringify({"message": "Hello World"})
};
callback(null, response);
};