The browser shows a CORS error only when the API returns 401 or 4XX, while successful calls work.
AdvancedTroubleshootingRoute 53, CloudFront, API Gateway and Messaging
Answer
Likely causes → The Lambda adds Access-Control-Allow-Origin to its own responses, but errors produced by API Gateway itself (authorizer denies, throttling, missing routes) are gateway responses without CORS headers. The browser then hides the real 401 behind a CORS error.
Diagnose →
curl -i -X GET https://abc123.execute-api.us-east-1.amazonaws.com/prod/me -H 'Origin: https://app.example.com'
aws apigateway get-gateway-responses --rest-api-id abc123 --query 'items[].[responseType,responseParameters]'
Fix →
aws apigateway put-gateway-response --rest-api-id abc123 --response-type DEFAULT_4XX \
--response-parameters '{"gatewayresponse.header.Access-Control-Allow-Origin":"'"'"'https://app.example.com'"'"'"}'
aws apigateway create-deployment --rest-api-id abc123 --stage-name prod
Do the same for DEFAULT_5XX. On HTTP APIs, use the built-in CORS configuration, which covers this.
Prevent → Define CORS once at the API level in IaC, and test error paths from a browser origin.
More on Route 53, CloudFront, API Gateway and Messaging
You created a public hosted zone and records for `example.com`, but `dig example.com` returns `NXDOMAIN` or old records.Beginner`InvalidChangeBatch: RRSet of type CNAME with DNS name example.com. is not permitted at apex in zone example.com.`BeginnerThe primary Region is down, but Route 53 failover records still send traffic to it.IntermediateA Route 53 health check reports `Failure: Connection timed out` for an endpoint that works fine from your laptop.IntermediateYou changed an A record an hour ago, but some users still reach the old server, and a newly created name returned `NXDOMAIN` for a while.AdvancedCloudFront returns `403 AccessDenied` (S3 XML) for every object after you switched the S3 origin to Origin Access Control.Intermediate