Fix CORS on AWS Lambda
CORS on AWS Lambda requires configuration in two places: API Gateway (to handle the OPTIONS preflight) and your Lambda function (to return CORS headers on every response). Missing either one causes CORS errors.
Test your Lambda CORS config live →HTTP API (API Gateway v2) — Recommended
HTTP API has built-in CORS support. Configure it in thole under your API → CORS, or via SAM/CDK:
HTTP API handles OPTIONS preflight automatically when CORS is configured. You do not need to add OPTIONS methods manually.
Lambda Function — Return CORS headers on every response
Even with API Gateway CORS configured, your Lambda function must return CORS headers on every response — including error responses. Otherwise browsers show a CORS error when your function returns a 4xx or 5xx.
REST API (API Gateway v1)
REST API requires manual OPTIONS method configuration on each resource. In the AWS Console: select your resource → Actions → Enable CORS. This creates the OPTIONS method and sets the required headers.
Lambda Function URLs
Lambda Function URLs have their own CORS configuration, separate from API Gateway. Set it when creating or updating the Function URL:
Common causes of CORS errors on Lambda
OPTIONS preflight returns 403 or 404 — REST API does not have an OPTIONS method on the resource. Enable CORS in the console or add the method manually.
CORS works for GET but fails for POST — POST with a JSON body triggers a preflight. Check that OPTIONS is configured and deployed.
CORS error on 500 responses — Lambda threw an error and the error response does not include Caders. Add CORS headers to your error handling code.
allow_origins=["*"] not working with credentials — Wildcard origin cannot be used when the request includes credentials (cookies or Authorization headers). Specify the exact origin.