- Newest
- Most votes
- Most comments
As you indicate, the problem seems to be related to the existing CORS policies in your API gateway. This ones should be configured to allow CORS request from your browser to the API via the S3 website. For that, the proper HTTP headers have to be sent by the browser in the preflight request (Detailed info in Mozilla CORS reference).
Please check the CORS documentation for API Gateway.
Specifically look at this two options (depend on the type of integration that you are using for your lambda), to ensure that you have properly set up your CORS configuration:
Enabling CORS support for Lambda or HTTP non-proxy integrations and AWS service integrations
For a Lambda custom (non-proxy) integration, HTTP custom (non-proxy) integration, or AWS service integration, you can set up the required headers by using API Gateway method response and integration response settings. When you enable CORS by using the AWS Management Console, API Gateway creates an OPTIONS method and attempts to add the Access-Control-Allow-Origin header to your existing method integration responses. This doesn’t always work, and sometimes you need to manually modify the integration response to properly enable CORS. Usually this just means manually modifying the integration response to return the Access-Control-Allow-Origin header.
Enabling CORS support for Lambda or HTTP proxy integrations
For a Lambda proxy integration or HTTP proxy integration, you can still set up the required OPTIONS response headers in API Gateway. However, your backend is responsible for returning the Access-Control-Allow-Origin and Access-Control-Allow-Headers headers, because a proxy integration doesn't return an integration response. Example code here.
If you need extra help, you can also check this CORS Troubleshooting guide.
Relevant content
- asked 9 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 months ago
What is the Integration Request you have configured in API Gateway? Is it a proxy integration?