CORS setup on AWS APIGateway
It has been also two month sicne my last update. There is no execuse, but I do want to claim that I have been out of home fro Aug 1st to 22nd, and got totally swampped after that for some LLM related work before Ray Summit.
Building a demo was one of them, and while working with AWS API Gateway, I met CORS authentication issue AGAIN
No surprise, CORS was one of the most common problem when you set up API gateway for endpoints. and this time I am recording what’s the proper way to solve it
1, Enable CORS in API Gateway
This is the most obvious step to do, and just follow instructions on the console and use default options.An OPTION
method will be added as MOCK
integration type
2 Add modify the API resources
Now you need to modify Integration reqeust
and Integration response
for the OPTION
method. I believe this is the key step to make CORS work. Some posts say you also need to modify Header mappings
, and I also did, but Im not sure if it’s necessary.
Even though Im not fully understand the 4 steps here, especially the differences between Method vs Integration, the Mapping templates
need to be filled with proper json responses.
- for
Integration reqeust
, add{"statusCode" : 200}
- for
Integration response
, add{"statusCode" : 200, "message": "Go ahead without me"}
3 Test CORS
https://test-cors.org is a simple website to test out your CORS setups. Using POST
method and you are espected to see status 200.