How to Create a CloudFront Download Distribution with AWS S3

How to Create a CloudFront Download Distribution with AWS S3

AWS CloudFront is a content distribution service offered by AWS to speed up the distribution of static or dynamic content, such as media files, html, js css, etc as well php. CloudFront serves its content through edge locations. As of Dec 2021, AWS had more than 35+ edge locations across the globe. When the user requests for any static content from CloudFront, it will find the nearest edge location to the user and deliver the content from that edge location to reduce the latency.

The present guide demonstrates how to create a download distribution with the AWS S3 service for CloudFront.

CloudFront can serve the content from AWS S3, the user’s own origin server or AWS services, such as EC2, and ELB. In CloudFront, the content is organized into distribution, which specifies the origin or location of the object (AWS S3 bucket or own origin).

1. Create a bucket with AWS S3. Make the bucket publicly accessible with the access policy.

2. Upload the media (image) file to be distributed using CloudFront to the bucket, and make it public.

3. Go to the AWS console through Click on “CloudFront”.

4. In the CloudFront console, click on “Create Distribution”.

5. In the Create Distribution wizard, select the download distribution. CloudFront also supports the streaming of media files. The present guide explains how to distribute an image file using CloudFront. Click on “Continue”.

6. Provide the origin ID as the bucket name created in step #1. At present accept the default values for “Restrict Bucket Access”.

7. Select the default values of cache behaviors in the same page. In cache behaviors, configure values for:

a. Path pattern is used to apply the cache behavior to specific objects. If default (*) is selected it will forward all requests to the bucket selected in step #6.
b. Viewer Protocol Policy allows the end user to access objects through HTTP and HTTPS.
c. Allow everyone to view the content through “Restrict User Access”.
d. Object Caching allows caching of objects up to 24 hours for the default value. To specify the time, use the customize option.
e. Forward Cookie is for AWS EC2 and the customized origin. It allows customizing whether the user wants to forward cookies to the origin server.
f. The Forward Query string is used to receive different versions of the object based on a query string in the URL.

8. Provide values for the distribution setting as given below:

a. Price Class: Allows the user to select the maximum price to pay for the CloudFront service.
b. CNAMEs allows the user to use URLs for objects instead of the domain name that CloudFront assigns. Thus, instead of the CloudFront distribution , the user can specify a custom URL.
c. Default Root Object serves the default root object when the user requests the root URL of the distribution (i.e. user sends request as instead of
d. Cookie Logging is used to allow origins other than AWS S3.
e. Comment is used to describe the distribution.
f. Distribution State, when enabled, allows CloudFront to process requests as soon as the distribution is created.

Click on the “Create Distribution” button after providing values, as explained in steps # 6, 7 and 8.

9. CloudFront will now create the distribution. It takes about 5-10 minutes to create a distribution. Initially, when the distribution is being created, the status will be “In Progress”.

10. Once the distribution has been created, the status will change to “Enable”. The distribution has now been created. Get the domain name of the distribution. The domain name for the download distribution will start with ‘d’ and be in the following format: “”.

11. To test the CloudFront distribution, first create a HTML file which uses the distribution and requests the image uploaded to the origin bucket, as explained in step #2.

12. When the HTML is requested, it will show the image. The object uploaded in step #2 will be served from the CloudFront edge location and not directly from the S3 origin. The image delivered through CloudFront is marked in the figure given below.

Keywords: Amazon Web Services, AWS, Amazon AWS Console, AWS S3, Amazon CloudFront, AWS CloudFront, CloudFront, AWS EC2, AWS ELB, CDN, Content Delivery Network

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!