Search code examples
amazon-web-serviceshttp-redirectamazon-s3routesamazon-cloudfront

AWS CloudFront how to follow S3 bucket redirection rules?


I have a Static web hosting bucket in which I have set redirection rules in a way that all requests to - bucket_endpoint/api/* are forwarded to api.anotherdomain.com so when I try to access the bucket directly using the bucket endpoint I see that the redirect works but when I tried to use CloudFront to deliver the contents of this bucket and since it is an angular app so I had to set a default error behaviour for 404 is redirect to /index.html with 200 status so cloudfront_domain/api request are redirected to this index.html I think right now instead of redirecting to the host specified by the S3 redirection rules.

So, can this be done in a way that S3 hosts the website and CloudFront redirects all traffic from a subpath like /api to another backend server ?


Solution

  • You need to add a second origin to your distribution and then create a new behavior with the path pattern you desire e.g. /api