CyberKeeda In Social Media
Showing posts with label CloudFront. Show all posts
Showing posts with label CloudFront. Show all posts

CloudFront : How to host multiple buckets from single CloudFront domain

As far if you follow this blog's posts, here mostly posts are related to cloud tasks assigned to me as an requirement, you can think as one of the industry standard requirements too.

In this blog post, we will see how we can achieve the above scenario that is One CloudFront domain to host multiple S3 buckets as origin.

Let's follow the steps as follow.

Create 3 different S3 buckets as per above architecture diagram.

As per the architecture diagram, create respective directories to match the URI path that is

  • --> s3-web1-bucket --> Create web1 directory inside s3-web1-bucket/
  • htttp:// --> s3-web2-bucket --> Create web2 directory inside s3-web2-bucket/

Dump 3 individual index.html files, that resembles to be an identifier as content served from that specific bucket.

  • index.html path for s3-web-bucket -- s3-web-bucket/index.html
  • index.html path for s3-web1-bucket -- s3-web-bucket/web1/index.html
  • index.html path for s3-web2-bucket -- s3-web-bucket/web2/index.html

This is how my three different index.html looks like.

We are set from the Bucket part, let's jump to CloudFront and create a basic CloudFront distribution with one of the s3 bucket as origin, here we have chosen s3-web-bucket as our origin for CloudFront distribution with other default settings.

Note : Default root object to index.html, else we have to append index.html manually every time after /

Now here comes the fun, we have our CloudFront URL in active state and thus according to our architecture this is what we are expecting overall.

Create Origins for S3 buckets.

Let's add other two more origin, which are the two other remaining s3 buckets.

Origin Configuration for S3 bucket "s3-web1-bucket"

Origin Configuration for S3 bucket "s3-web2-bucket"

Create Behaviors for the above origins.

So far, we have added all the s3 buckets as origin, now let's create the behavior which is path aka URI based routing.

Behavior 1 - /web1 routes to s3-web1-bucket

Behavior 2 - /web2 routes to s3-web2-bucket

Overall, within the Behavior tab, it should look as below  

That's it !
Let's Open Browser and test the urls one by one.

Hope this will help you in some sort !
Read more ...
Designed By Jackuna