cloudfront path based routing

0

I have a S3 bucket with static website enabled which is being used as an origin for the Cloudfront distribution.. so currently if I send a request to my domain(mapped with cloudfront distribution) test123.com it gives me the index.html for the configured static website in the s3 but I have some new requirements such that if the path is test123.com/v2/ or test123.com/v2/anything it should give me the /v2/index.html from the same bucket. I am new to S3 and cloudfront, please help me with this.

1 Answer
3

Hello.

I have some new requirements such that if the path is test123.com/v2/ or test123.com/v2/anything it should give me the /v2/index.html from the same bucket.

CloudFront sends the actually entered path to the origin (S3), so you need to access it in the browser as follows.

https://test123.com/v2/index.html

If you want to omit the file name index.html, you need to use a feature called CloudFront Function as described in the document below.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example-function-add-index.html

By the way, you don't need to use static website hosting when using S3 as your CloudFront origin.
As shown in the document below, it is possible to distribute web content while restricting access using a function called OAC.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html

profile picture
EXPERT
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
profile pictureAWS
EXPERT
reviewed 2 months ago