Serve static content from S3 with CloudFront

M Rayyan
2 min readMar 26, 2023

--

Using Amazon Simple Storage Service (Amazon S3) is a cheap and effective way to host static websites and other web content.You can do so directly from the S3 console by enabling the Static website hosting feature and you’ll get a website.More likely the solution will evolve toward serving content from edge cache locations using CloudFront.

CloudFront:

Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content.CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you’re serving with CloudFront, the request is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.

The steps we follow to achieve this solution are;

  • Register a domain name in Route53.
  • Create an Amazon S3 bucket and configure it to host a website.
  • Enable static website hosting option.
  • Set the policy that grants access to the objects in the specified bucket.
  • Create a sample website and upload the file in your S3 bucket.
  • You can now access the page with bucket endpoint.
  • Now point it to our domain, create CNAME pointer to the domain that redirects the traffic to our S3 bucket.
  • Now test your website with domin name.
  • Create a certificate for your domain in ACM.
  • Configure CloudFront distributions for S3 bucket.
  • In cloudfront SSL certificate is consume from ACM.
  • Now you can access your website in secure mode.

References:

https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/getting-started-cloudfront-overview.html https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html

https://www.youtube.com/watch?v=fMhj20GbmMM

--

--