Unable to figure out 502 error - AWS/CF/Custom Origin

243 views Asked by At

Brief history: I recently moved to new AWS account. And I ported all settings to new account - Route53, CF distributions, S3 buckets, new EC2 instance, RDS etc.

I've managed to make most of it work except for accessing APIs hosted on an EC2 instance on Node running Express server. Note: I AM able to access via ip address (e.g. ipaddress:8000/api/v1). However, not with the domain name - theplaybook.rocks/v1/ap1.

The apex domain works properly (the frontend hosted on S3 with static website hosting and served via CF distribution configured with DNS records) - [theplaybook.rocks][1] works fine.

In the CF distribution I have 2 Origins

  1. S3 static website - configured with behaviour default path
  2. EC2 Custom Origin - configured with behaviour /api/* path

Alternate domain names - configured Security policy - TLSV1 (Tried 1.1 as well) Origin Protocol Policy (for EC2 origin) - HTTP only Behaviour for EC2 origin (points I think may help in answering this problem):

  1. Viewer Protocol Policy - HTTP & HTTPS
  2. Cache Based on Selected Request Headers - ALL
  3. Forward Cookies - ALL
  4. Query String Forwarding and Caching - Forward All, cache based on all

It seems like the CF is unable (or doesn't want to) connect to the Custom Origin.

TLDR:-

http://3.15.153.208:8000/api/v1 works (public IP - so problem is probably not with node/express and ports).

http://theplaybook.rocks/api/v1/ does not work, actually it used to work from different AWS account, just not in new configuration.

PS:- I had the same problem in the old account. And I solved it somehow. And I can't remember how I solved it anymore.

Please help... and I can share more info... let me know. Tks.

2

There are 2 answers

0
Anwin Joselyn On

Solved. Finally.

I changed HTTP port to 8000 (instead of 80) in Origin settings and it started working immediately.

Note: Previously this was not the case. I never used to put 8000 port here. Not sure why now.

Thanks everyone who glanced by this post :-D

5
louisbuchbinder On

Try adding an alternate domain name to your cloud front distribution: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html