Create CloudFront Distribution
A step-by-step guide to setting up your first Amazon CloudFront distribution to serve content from an S3 bucket.
Overview
A CloudFront distribution is the mechanism that tells CloudFront where to find your content (the "origin") and how to deliver it to your users. This guide will walk you through creating a distribution that serves content from an Amazon S3 bucket.
Prerequisites
- An active AWS account
- An S3 bucket with some objects (files) in it
Step 1: Access CloudFront Console
First, navigate to the CloudFront service in the AWS Management Console.
- Sign in to the AWS Management Console
- In the search bar, type "CloudFront" and select "CloudFront" from the dropdown
- Click the "Create a CloudFront distribution" button
Step 2: Create a Distribution
Now, you'll configure the settings for your new distribution.
Origin Domain
This is the source of your content.
- Under "Origin domain", click the input field and select your S3 bucket from the list
S3 Origin Access
This setting controls how CloudFront accesses your S3 bucket.
- Select "Origin access control settings (recommended)"
- Click "Create new OAC"
- Give the OAC a name, and leave other settings as default
- Click "Create"
AWS will generate a bucket policy for you to copy and apply to your S3 bucket. Follow the on-screen instructions to copy the policy and paste it into your S3 bucket's permissions tab under "Bucket Policy". This is a critical step for security.
Default Cache Behavior
This section defines how CloudFront caches your content.
- Viewer protocol policy: Select "Redirect HTTP to HTTPS" for secure connections.
- Allowed HTTP methods: Select "GET, HEAD" for most static content.
- Caching policy: Use the default "Managed-CachingOptimized" for a simple setup.
Distribution Settings
Configure general settings for your distribution.
- Price class: "Use all edge locations (best performance)" is recommended for global reach, but you can choose a lower-cost option if your users are in a specific region.
- Alternate domain name (CNAME): You can add a custom domain name here (e.g., cdn.your-domain.com).
- Default root object: If you are hosting a static website, set this to "index.html".
Step 3: Wait for Deployment
After creating the distribution, its status will be "Deploying". This process can take several minutes. You can monitor the status on the CloudFront distributions list.
Step 4: Test the CDN URL
Once the status changes to "Enabled", your distribution is ready.
- Click on your distribution ID to view its details
- Find the "Distribution domain name" (e.g., d12345.cloudfront.net)
- To test, append the name of a file from your S3 bucket to this domain name (e.g., d12345.cloudfront.net/your-file.jpg) and visit it in a browser
If everything is configured correctly, the file will be served from CloudFront's global network.
Next Steps
Your content is now being delivered by CloudFront. You can:
- Set up a custom domain name for your distribution
- Explore advanced caching and security settings
- Learn about IAM to manage access to your AWS resources