This is a duplicate question, in the sense that it is about an issue I've read about in plenty of other stackoverflow posts already. However, none of the solutions I found seem to work for my particular configuration, which is why I wanted to ask again with my own details.
I have set up an S3 bucket, containing my html/javascript for my website. I made this bucket open for all to see, and added the following CORS policies on it:
[ { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "GET", "POST", "OPTIONS" ], "AllowedOrigins": [ "*" ], "ExposeHeaders": [] } ] The core of my service's functionality, however, lies in a Lambda function (which internally communicates with DynamoDB). To access this Lambda function from my S3-hosted website, I also added an API gateway.
Firstly, I added the following in my Lambda request handling:
const headers = { 'Content-Type': 'application/json', 'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'OPTIONS,POST,GET', }; The headers are later returned as part of the request result.
My API Gateway is quite simple, and is just composed of one single URL, configured as follows:
Furthermore, I enabled CORS on this API Gateway like so:
When I click on "Stages", some other request methods appear as well, but I don't think they are enabled/matter:
So, basically, I have enabled CORS on 3 different points: On my S3 bucket, in my Lambda code, and on the API Gateway. Yet, when I try to access my Lambda function by sending a POST-Request to my API Gateway from the website on my bucket, I get the following error: Access to XMLHttpRequest at 'https://----.execute-api.eu-west-3.amazonaws.com/default/----' from origin 'http://------.s3-website.eu-west-3.amazonaws.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
And, well, I simply don't know how to continue. I've read the CORS Docs of AWS, and I've scrolled Stackoverflow extensively, yet I don't seem to be able to reproduce a working environment myself...


