How to Enable CORS for an AWS API Gateway Resource

后端 未结 1 750
无人及你
无人及你 2021-01-20 04:20

I created REST API using AWS API Gateway & AWS Lambda and when I configured CORS I faced with such issue - I was able to configure CORS response headers for OPTIONS meth

相关标签:
1条回答
  • 2021-01-20 05:08

    Since you're using Lambda Proxy integration for your method, you'll need to:

    (1) provide the Access-Control-Allow-Origin header as part of the Lambda response. For example:

    callback(null, {
        statusCode: 200,
        headers: {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"},
        body: JSON.stringify({message: "Success"})
    });
    

    (2) and add the Access-Control-Allow-Origin as a 200 response header in your Method Response config.

    0 讨论(0)
提交回复
热议问题