I have set up Cloudfront for path based routing between an Amplify app and an EC2 instance. When a user accesses the root domain, it will show him the Amplify app. If the /api path is added to domain, it will route to EC2 instance.
Everything worked as expected when I used the Coudfront default domain. But the problem began when I add my own domain to Cloudfront.
I set up public hosted zone on Route53 and add an alias to the CloudFront. The Amplify app is showing in the root domain. But when I try to access the /api path, it throws too many redirect error.
I have whitelisted the host header on the behavior corresponding to /api path. Also some subdirectories is deleting the root domain altogether. For example, if I enter domain.com/api/get it removes the domain.com and accesses the api/get. It’s kind of weird but I don’t know why it occurs.
I used to use the current domain to access ec2 before.
Did anyone face the same issue? what might be wrong here?
Too-many-redirects tells me that the application behind Cloudfront is not recognizing the Host header and is attempting to redirect back to the name it thinks it should be, and the process repeats.
I’ve also seen this with an application that handles redirection to https, where the https was terminated at the CF distribution, causing and endless loop, hence to many redirects.