S3 Static Website with CloudFront

Serving up an image with S3 and CloudFront…

Amazon S3 is a storage service for objects and CloudFront is a content delivery network. Together, you can create a static website with low latency for optimal performance.

We will do this using a photo, stored in an S3 bucket, and then we will display it on a website using CloudFront.

Let’s start by —

Create your S3 Bucket…

Navigate to S3 on your AWS console and select “Create Bucket”. You will have to choose a globally unique name. Mine will be “headinthecloudbucket”. When you have done that, then choose the region you would like it in. I am going to be in “us-east-1”. Then scroll down and select “Create Bucket”.

Next, go into your new bucket and click “Upload”. Choose a photo to put into the bucket, and when it is recognized, select the box next to the file you chose and select “Upload” again.

When the file is uploaded, we are going to name the object “index.html”. You can do this by clicking on the object you uploaded, and then choose the “Object actions” dropdown and select “Rename object”.

Next, navigate to the “Properties” section of your bucket, and scroll to the bottom where it says, “Static website hosting”. Select “Edit”, and then “Enable”. Where is says, “Index document”, write “index.html” (this is our picture we uploaded). Go ahead and save, and make your way to the CloudFront dashboard.

From the CloudFront dashboard…

Select “Create a CloudFront distribution”, select your bucket as “Origin domain”, and under S3 bucket access choose “Yes use OAI”. Then you can select “Create new OAI”, and select “Yes, update the bucket policy”. Scroll down a ways and where it says, “Default root object” write in your “index.html” object again.

Note: Under "Settings" you can also select a "Price class" which allow you to pick which type of edge location option you'd like. For the best performance we will stick with "Use all edge location". 

Finally choose “Create distribution”!

This may take awhile, but once CloudFront no longer says “Deploying”, copy the “Distribution domain name” — and paste it into another tab to see if your photo shows up!

You can take a look at mine HERE!

I hope this was helpful (and fun!). Thanks for reading.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store