502 errors while accessing CloudFront distribution that's connected to a load balancer

1

I have configured a CloudFront distribution to point to an application load balancer (ALB). The ALB points to a lambda function. I have configured an A record in Route53 to point to the CloudFront distribution. Hitting the ALB directly via its generated domain name, works (ie. the lambda is hit and runs and returns OK). Attempting to hit the application via the domain and CloudFront returns a 502 error:

502 ERROR
The request could not be satisfied.
CloudFront wasn't able to connect to the origin. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

How can I best troubleshoot this? Are there any frequent pitfalls I might have fallen in to?

3 Answers
2

Did you check all of the possible causes listed in the docs?

Do you have VPC Flow logs enabled, and does that give any indication as to what's happening?

AWS
EXPERT
Paul_L
answered 2 months ago
0

Other than the above check list, you should also check if ALB has any whitelist of supported domain names, in this case your distribution supported domain name For example F5 LB can allow or deny certain HOST values if not explicitly whitelisted

Anand
answered 2 months ago
0

Besides documentation, you can refer to How do I troubleshoot a 502: "The request could not be satisfied" error from CloudFront?.

Are you accessing your ALB directly via HTTP or HTTPS? If this is HTTP only, edit your CloudFront Origin Protocol to HTTP only

You may also want to change CloudFront Behavior to CachingDisabled

AWS
EXPERT
Mike_L
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions