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

CloudFront shows `502 ERROR. The request could not be satisfied. CloudFront wasn't able to connect to the origin.`

IntermediateTroubleshootingRoute 53, CloudFront, API Gateway and Messaging
Answer

Likely causes → The CloudFront → origin TLS handshake fails: the origin certificate does not match the origin domain name, it is self-signed or expired, or the chain is incomplete. Or the origin protocol policy is wrong (HTTPS-only to an origin that only speaks HTTP), or the SG blocks CloudFront.

Diagnose →

aws cloudfront get-distribution-config --id E123ABC \
  --query 'DistributionConfig.Origins.Items[].[DomainName,CustomOriginConfig]'
openssl s_client -connect origin.example.com:443 -servername origin.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -dates

Fix →

  1. Use an origin domain covered by a valid public certificate (for example, an ACM certificate on the ALB for origin.example.com), and forward the matching Host or SNI
  2. Match the origin protocol policy and ports to what the origin serves
  3. Allow the com.amazonaws.global.cloudfront.origin-facing prefix list on the ALB SG

Prevent → Monitor origin certificate expiry, and use CloudFront VPC origins or origin-facing prefix lists for ALB origins.

aws All AWS questions Roadmap: AWS core services

More on Route 53, CloudFront, API Gateway and Messaging