Deliver Content Faster with HAQM CloudFront
Introduction
Implementation
Prepare your content
In this step, we will upload sample static content to an HAQM S3 bucket. In later steps, we will use this bucket as a CloudFront origin. HAQM S3 is a good choice for an HAQM CloudFront origin that includes static content such as images, videos, HTML pages, .css files, and .js files.
2. Enter the HAQM S3 console
When you click here, the AWS Management Console will open in a new browser window. Type S3 in the search bar and select S3 to open the console.

3. Create S3 bucket
In the S3 dashboard, choose Create bucket.
If this is the first time you have created a bucket, you will see a screen that looks like the image pictured here.
If you have already created S3 buckets, your S3 dashboard will list all the buckets you have created.

4. Enter bucket name
Enter a unique bucket name. Bucket names must be unique across all existing bucket names in HAQM S3. There are a number of other restrictions on S3 bucket names as well. Then select a Region to create your bucket in.

5. Set permission settings
You have the ability to set permission settings for your S3 bucket. By default, S3 objects are set to private. You will need to make your image publicly readable. Select ACLs enabled under Object Ownership, deselect “Block all public access” and select the checkbox “I acknowledge that the current settings might result in this bucket and the objects within becoming public.”

6. Create the bucket
You have many useful options for your S3 bucket including Versioning, Server Access Logging, Tags, Object-level Logging and Default Encryption. We won't enable these features for this tutorial.
Select Create bucket.

8. Select Upload
You are in your bucket’s home page.
Select Upload.

9. Upload sample content
Upload the cloudfront-test-image.png file by selecting Add files and selecting the file or dragging the cloudfront-test-image.png file to the upload box.
Open the Permissions dropdown. Select Choose from predefined ACLs and then select Grant public-read access. Select the checkbox “I understand the risk of granting public-read access to the specified objects.”
Select Upload.

Enter the CloudFront console
1. Open the CloudFront console
When you click here, the AWS Management Console will open in a new browser tab. Type CloudFront in the search bar and select CloudFront to open the console.

2. Create a CloudFront distribution
Select Create a CloudFront distribution.

Configure a web distribution
1. Configure settings
You will now configure your settings.
In, Origin domain select the name of the S3 bucket you stored cloudfront-test-image.png in.
You can leave the rest of the configuration settings with the default values for this tutorial. If you would like to learn more about each configuration setting, please read below.
Learn More About Configuration Settings
Default cache behavior settings:
Distribution settings:
Price class: CloudFront has three Price Classes determined by the number of edge locations you want supported throughout the globe. By default, CloudFront uses all edge locations to ensure the best performance. For more information, see HAQM CloudFront Pricing.
AWS WAF web ACL: If you want to allow or block HTTP and HTTPS requests based on criteria you specify, choose the web ACL to associate with this distribution. For more information, see the AWS WAF, AWS Firewall Manager, and AWS Shield Advanced Developer Guide.
Alternate domain name (CNAME): CloudFront will automatically assign you a domain name when you create a web distribution (for example, http://abcdefghi888.cloudfront.net/filename.jpg). You can also specify your own domain name in the URLs for your objects (such as http://yourDomain.com/filename.jpg) once you update your DNS configuration to route DNS queries to your CloudFront distribution. For this tutorial, leave this field blank.
Custom SSL certificate: CloudFront provides a default certificate or you can specify custom SSL certificate.
Default root object: This is where you specify the object that you want CloudFront to request from your origin when a user requests just the root URL of your distribution. For example, a user requests http://www.example.com/, and you can specify that http://www.example.com/product-description.html is delivered. Specifying a default root object avoids exposing the contents of your distribution.
Standard logging: CloudFront can log information about each request for an object and store the log files in an HAQM S3 bucket. There is no extra charge to enable logging, but you accrue HAQM S3 charges for storing and accessing files.
Bucket for logs: If you specified an HAQM S3 bucket to store access logs in, CloudFront can record information about each user request for an object and store the files in the specified HAQM S3 bucket. You can enable or disable logging at any time. For more information about CloudFront access logs, see Access Logs.
Log prefix: If you chose On for Logging, you can specify the string that you want CloudFront to prefix to the access log filenames for this distribution. For more information about CloudFront access logs, see Access Logs.
Cookie logging: When using HAQM S3 as the origin for your objects, HAQM S3 doesn't process cookies, so unless your distribution also includes an HAQM EC2 or other custom origin, you need to select Off for the value of Cookie Logging. For more information about cookies, see Caching content based on cookies.
Description: You can enter any comments that you want to save with the distribution.

Create a distribution
1. Create and propagate the distribution
Once you configure your distribution, CloudFront will create the distribution and propagate it throughout the CloudFront network for you to use. Select Create distribution.
After this process is complete, your status column will change from In Progress to Enabled.
Note: This can take a few minutes to complete.
The domain name that CloudFront assigns to your distribution appears in your list of distributions. Keep this in mind, you will need it for the next step. Clicking on the Distribution ID field takes you to a page where you will see the full CloudFront domain under Domain Name.

Test your link
After you create your web distribution, you can test it out by confirming that CloudFront gets your object from the origin and returns it to a web browser. For this test, you will need the CloudFront domain name from Step 4 and the image name you uploaded to the S3 bucket in step 1.
1. Create an HTML file
Open a text editor on your computer. Copy and paste the following HTML code:
<html>
<head>My CloudFront Test</head>
<body>
<p>My text content goes here.</p>
<p><img src="http://domain name/object name" alt="my test image">
</body>
</html>
Replace domain name with the domain name that CloudFront assigned to your distribution, such as d111111abcdef8.cloudfront.net.
Replace object name with the name of your image file in the HAQM S3 bucket - in our case, cloudfront-test-image.png.
Save the text in a file as mycloudfronttest.html.
Open your HTML file in a web browser to verify that the link works.

Disable and delete your distribution
1. Select the distribution to disable
Select the checkbox next to the distribution you created and choose Disable.

2. Confirm disabling the distribution
You will be asked to confirm. Choose Disable.

3. Select the distribution to delete
Select the checkbox next to the distribution you created and choose Delete.

4. Confirm deleting the distribution
You will be asked to confirm. Choose Delete.

Conclusion
You created your first HAQM CloudFront web distribution and delivered a piece of static content hosted in the cloud through HAQM S3. With a few configuration changes, you can use CloudFront to deliver dynamic content, live events such as a meeting, conference, or concert, in real time over HTTP or HTTPS. Use HAQM Cloudfront to speed delivery of your entire website or application, including dynamic, static, streaming, and interactive content.
Did you find what you were looking for today?
Let us know so we can improve the quality of the content on our pages