How do I resolve CORS and Terraform deployment issues with API Gateway?
Last updated: May 13, 2025
Context
When deploying API Gateway configurations through Terraform, you may encounter two common issues:
CORS errors due to case-sensitive header configurations
API Gateway changes not taking effect after Terraform apply
Answer
To resolve CORS-related issues:
Ensure header names in your API Gateway configuration match exactly the case expected by the client. For example, use 'x-tenant-id' instead of 'X-Tenant-Id'.
Include all required headers in your CORS configuration. Common headers include:
Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Client-Id,X-Amz-Security-Token,X-Csrf-Token,x-tenant-id,x-csrf-token
If API Gateway changes are not taking effect after Terraform apply:
A manual redeployment of the API Gateway stage may be necessary to propagate the changes.
To manually redeploy:
Go to the AWS Console
Navigate to API Gateway
Select your API
Choose the stage that needs updating
Click "Deploy API"
Note: While manual redeployment can resolve immediate issues, consider updating your Terraform configuration to include automatic redeployment of the API Gateway stage after configuration changes.