Interview Prep/AWS/Route 53, CloudFront, API Gateway and Messaging

A REST API returns `{"message":"Forbidden"}` (403) to a client that sends the right path.

IntermediateTroubleshootingRoute 53, CloudFront, API Gateway and Messaging
Answer

Likely causes → The method requires an API key and the x-api-key header is missing, or the key is not in a usage plan tied to this stage. For a private API, the call does not come through the allowed VPC endpoint, or the resource policy denies it. A WAF rule may also block it.

Diagnose →

aws apigateway get-method --rest-api-id abc123 --resource-id res1 --http-method GET --query apiKeyRequired
aws apigateway get-usage-plans --query 'items[].[name,apiStages]'
aws apigateway get-rest-api --rest-api-id abc123 --query '[endpointConfiguration,policy]'

Fix →

  1. Send x-api-key, and link the key to a usage plan with this stage: aws apigateway create-usage-plan-key --usage-plan-id up1 --key-id k1 --key-type API_KEY
  2. For private APIs, call through the execute-api VPC endpoint and allow aws:SourceVpce in the resource policy

Prevent → Do not use API keys as authentication (use IAM, Cognito or JWT authorizers), and turn on access logging with $context.error.responseType.

aws All AWS questions Roadmap: AWS core services

More on Route 53, CloudFront, API Gateway and Messaging