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:

  1. CORS errors due to case-sensitive header configurations

  2. API Gateway changes not taking effect after Terraform apply

  3. Answer

    To resolve CORS-related issues:

    1. 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'.

    2. 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:

    1. A manual redeployment of the API Gateway stage may be necessary to propagate the changes.

    2. 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.