DEV Community

Tim Nguyen
Tim Nguyen

Posted on

CloudFront + S3 + Static domain routing

What are existing:

  • S3 bucket 1: xxx.s3.us-east-1.amazonaws.com
  • S3 bucket 2: yyy.s3.us-east-1.amazonaws.com
  • Domain name: abc.com

What is requiring:

  • Using only 1 static domain name: static.abc.com
  • Using only 1 CloudFront distribution to serve both S3 buckets above with prefix (S3 bucket 1 - prefix admin and S3 bucket 2 - prefix public)
  • Eg: What is served with https://xxx.s3.us-east-1.amazonaws.com/img.jpg can be served with https://static.abc.com/admin/img.jpg and what is served with https://yyy.s3.us-east-1.amazonaws.com/img.png can be served with https://static.abc.com/public/img.png

Idea

  • Create a distribution in CloudFront with 2 origins are 2 bucket above
  • Create 3 distribution behaviors:
    • /admin/* - To Distribution's Origin of S3 Bucket 1
    • /public/* - To Distribution's Origin of S3 Bucket 2
    • Default(*) - To either Origin of S3 Bucket 1 or Origin of S3 Bucket 2
  • Modify 3 distribution behaviors to have function associations to Lambda@Edge function (this will be in another post, but the document for create one here)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay