Configuring API Gateway for CORS
Understand how to set up CORS in AWS API Gateway for serverless applications by adding OPTIONS handlers and configuring static or dynamic responses with SAM. Learn to update Lambda functions to handle CORS headers and environment variables to enable secure cross-origin requests.
We'll cover the following...
OPTIONS handler #
The CORS request going from the web page to your API is going to be a bit more tricky. You’ll need to add an OPTIONS handler to the API and also change the response in your function to include the correct origin.
There are two ways of configuring OPTIONS handlers. The first is to add a Lambda function and an API endpoint. This would make it fully flexible, so you could dynamically calculate the right origin and response headers, but it would add an API call and a Lambda execution to your costs. In cases where you don’t really need a dynamic ...