To set up Amazon CloudFront for your S3 bucket (to deliver content via a CDN), follow these step-by-step instructions:
✅ Step-by-Step: Set Up CloudFront for Amazon S3
🔹 Step 1: Prepare Your S3 Bucket
- Go to: https://s3.console.aws.amazon.com/
- Select or create a bucket.
- Optional – if you want the files to be public (for direct access):
- Go to Permissions tab.
- Click Bucket Policy and add:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}]
}
Replace your-bucket-name with your actual bucket name.
🔹 Step 2: Create a CloudFront Distribution
- Go to: https://console.aws.amazon.com/cloudfront/
- Click Create Distribution
- Under Web (Default), click Get Started
🔹 Step 3: Configure Origin
- Origin Domain Name: Select your S3 bucket (from dropdown – it should end in
.s3.amazonaws.com) - Origin Path: Leave empty unless you want to serve a subfolder
- Origin Access:
- ❗If your S3 bucket is private: Choose Create a new OAC (Origin Access Control) to restrict S3 access via CloudFront only
- If public: Leave this section as is
🔹 Step 4: Configure Settings
- Viewer Protocol Policy: Redirect HTTP to HTTPS or HTTPS only (recommended)
- Cache Policy: Use recommended or select/create a custom one
- Compress Objects Automatically: Yes
- Price Class: Choose based on your region (default is best)
🔹 Step 5: Create the Distribution
- Click Create Distribution
- Wait for status to change to Deployed (can take 5–10 minutes)
🔹 Step 6: Access Files via CloudFront
Once deployed, your distribution will have a Domain Name, such as:
d1abc2xyz3cloudfront.net
You can access your S3 files like:
https://d1abc2xyz3cloudfront.net/path/to/file.jpg