Serve Globally with CloudFront

CloudFront is AWS's CDN β€” it caches your site at edge locations worldwide for speed and HTTPS.

CloudFront is a Content Delivery Network. It copies your files to hundreds of edge locations around the world, so a user in Tokyo is served from Tokyo, not your one bucket in Virginia.

S3 plus CloudFront static site deliveryBrowseruserCloudFrontedge cache + HTTPSACM certTLS for domainS3 bucketorigin filesrequestcache miss
Requests hit the nearest CloudFront edge; misses fetch from S3.

Why put CloudFront in front of S3?

  • HTTPS on your custom domain via ACM.
  • Caching makes repeat loads near-instant.
  • Origin Access Control keeps the bucket private.

Example

Example Β· json
{
  "Comment": "myapp production site",
  "DefaultRootObject": "index.html",
  "Origins": [{
    "Id": "s3-origin",
    "DomainName": "myapp-prod-web-2026.s3.us-east-1.amazonaws.com",
    "OriginAccessControlId": "E1EXAMPLE123"
  }],
  "DefaultCacheBehavior": {
    "TargetOriginId": "s3-origin",
    "ViewerProtocolPolicy": "redirect-to-https"
  }
}

When to use it

  • A global SaaS product uses CloudFront so users in Tokyo get cached assets from a nearby edge location instead of hitting a US-East S3 bucket.
  • A media company serves video thumbnails through CloudFront to handle traffic spikes without overwhelming the origin.
  • A developer enables HTTPS on an S3 static site by putting a CloudFront distribution in front of it.

More examples

Create CloudFront distribution for S3

Creates a CloudFront distribution that pulls content from an S3 website endpoint and caches it globally.

Example Β· bash
aws cloudfront create-distribution \
  --origin-domain-name my-site-bucket.s3-website-us-east-1.amazonaws.com \
  --default-root-object index.html

CloudFront distribution config snippet

Shows the key parts of a CloudFront distribution config: locked-down S3 origin with OAI and HTTPS redirect.

Example Β· json
{
  "Origins": {
    "Quantity": 1,
    "Items": [{
      "Id": "S3Origin",
      "DomainName": "my-site-bucket.s3.amazonaws.com",
      "S3OriginConfig": { "OriginAccessIdentity": "origin-access-identity/cloudfront/ABCDEF" }
    }]
  },
  "DefaultCacheBehavior": {
    "ViewerProtocolPolicy": "redirect-to-https",
    "Compress": true
  }
}

Get distribution domain name

Lists all distributions with their domain names so you can verify the distribution is deployed.

Example Β· bash
# Retrieve the CloudFront domain after creation
aws cloudfront list-distributions \
  --query 'DistributionList.Items[*].[Id,DomainName,Status]' \
  --output table

Discussion

  • Be the first to comment on this lesson.
Serve Globally with CloudFront β€” AWS Deployment | SoundsCode