- Newest
- Most votes
- Most comments
You can use Amazon CloudFront with S3 bucket as the origin, and then set up different behaviors based on the subdomain. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DownloadDistS3AndCustomOrigins.html
Here are the steps:
-
Go to the CloudFront console and create a new distribution.
- Choose
Web
distribution. - For the origin, select your S3 bucket.
- Choose
-
Navigate to behaviors tab, for the first behavior (default), the path pattern can be
*
which will match everything. Set the origin path to/content
.- Create a second behavior with the path pattern
image/*
. Set the origin path to/content/image
. In your AWS Route 53, you need to create twoA
records:text.example.com
– Points to the CloudFront distribution you set up.image.example.com
– Points to the same CloudFront distribution.
- Create a second behavior with the path pattern
-
Wait for the CloudFront distribution to be deployed and test.
origin JSON file: my_s3_bucket->content/a.json
origin PNG file: my_s3_bucket/content/image/a.png
requesting JSON URL: https://text.example.com/abc/a.json
requesting PNG URL: https://image.example.com/a.png
there is no way you can use simply use origin and behavior configurations to achieve the result.
You can consider to use a CloudFront Functions (CFF) to rewrite the requesting path without modifying the requesting URL. You can use a single CFF or separate CFF.
In the behavior settings, create two behaviors, one behavior is " *.json" and another one is " *.png" (applying without double quote). Document source here. the origin can be the same, the S3 bucket.
In each behavior, associate with the CFF Viewer Function, based on the suffix, json or png, modify the path to match the path of file in origin S3 bucket.
for example, if the requesting path is content/a.json before be processed by CFF , the outcome path will be modified to 'abc/a.json'.
Relevant content
- asked 9 months ago
- asked 8 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 8 months ago