Our next-gen architecture is built to help you make sense of your ever-growing data. Watch a 4-min demo video!

CDN on AWS: the Basics and Setting Up a CloudFront Distribution

  • 7 min read

What Is a CDN? 

A Content Delivery Network (CDN) is a distributed network of servers designed to deliver web content to users based on their geographic location. By caching copies of content at various strategically placed data centers worldwide, CDNs minimize latency, reduce server load, and improve load times for web pages and media. 

This setup enhances the user experience by providing faster access to resources, increasing the reliability and availability of content. CDNs function by redirecting user requests to the nearest server in the network, optimizing the delivery path.

In this article, you will learn:

Amazon CloudFront: CDN on AWS 

Amazon CloudFront is a CDN service provided by Amazon Web Services, designed to deliver web content with high performance and security. As part of the AWS ecosystem, CloudFront integrates with other AWS services such as S3, EC2, and Lambda. 

CloudFront has a global network of edge locations to cache content closer to users, reducing latency and speeding up delivery times. It can serve static assets, streaming media, and dynamic content. The service includes built-in features like AWS Shield for DDoS protection, AWS WAF for application layer security, and SSL/TLS encryption to secure data in transit.

CloudFront automatically adjusts to handle traffic spikes, ensuring consistent performance during peak usage times. CloudFront’s pay-as-you-go pricing model allows organizations to optimize their costs based on actual usage.

AWS CloudFront Use Cases

Here are some of the main use cases for CloudFront:

  • Accelerating static website content delivery: Speeds up the delivery of static content, such as HTML, CSS, and JavaScript files, caching them in locations closer to the user.
  • Serving video on demand and live streaming video: By leveraging a global network of PoPs (Points of Presence), it offers low latency and high data transfer speeds, maintaining smooth video playback and reducing buffering. CloudFront supports various protocols for streaming, including HLS, HDS, and Smooth Streaming, providing flexibility in how content is delivered and consumed.
  • Customizing at the edge: CloudFront’s edge locations support custom code execution, enabling developers to tailor content delivery and perform computations closer to the user. Its real-time data processing and personalization capabilities are useful for dynamic content and interactive applications.

How CloudFront Delivers Content

CloudFront uses an extensive network of edge locations, distributed globally, to deliver content. When a user requests content, CloudFront directs the request to the nearest edge server, which checks its cache for the requested files. If the content is available in the cache, the edge server immediately delivers it to the user, speeding up the response time.

If the requested content is not in the cache, the edge server retrieves it from the origin server, which could be an Amazon S3 bucket, an HTTP server, or another web server. Once fetched, the content is cached at the edge location for future requests. This caching mechanism reduces the load on the origin server and ensures quicker delivery for subsequent requests.

CloudFront supports various methods for caching and content delivery, including time-to-live (TTL) settings, which dictate how long content should be cached before checking back with the origin server for updates. Its integration with AWS services supports features like Lambda@Edge, which lets developers run code closer to the end user.

Amazon CloudFront Pricing

Amazon CloudFront’s pricing model is based on the data transfers and requests involved in delivering content to customers. This pay-as-you-go structure ensures no upfront payments, fixed platform fees, or long-term commitments. Data transfers from AWS services like Amazon S3 or ELB incur no additional charges, and CloudFront offers a free tier for getting started.

Key factors influencing the cost of CloudFront include:

  • Data transfer out: Charges are based on the volume of data transferred out from CloudFront edge locations to the Internet or the origin server.
  • Requests: Pricing varies by the number and type of requests (HTTP or HTTPS) and the geographic region where the requests are made.
  • Invalidation requests: The first 1,000 paths requested for invalidation each month are free. After that, each additional path costs $0.005.
  • Field-level encryption requests: Additional charges apply for field-level encryption, costing $0.02 for every 10,000 requests that require this encryption, on top of the standard HTTPS request fee.
  • Dedicated IP SSL: Custom SSL certificates using dedicated IPs are billed at $600 per month per certificate, with charges prorated by the hour.
  • Real-time logging requests: CloudFront logs are charged at $0.01 per 1,000,000 log lines generated.
  • Lambda@Edge: This service incurs charges based on the number of invocations and the compute capacity used. Invocation pricing is $0.60 per 1 million invocations ($0.0000006 per invocation), and compute capacity is billed at $0.00005001 per GB-second used.

Tutorial: Getting Started with a Basic CloudFront Distribution

Before you begin, ensure you have completed the preliminary steps of setting up your AWS environment. This involves creating an AWS account, configuring a user with administrative access, and setting up the AWS Command Line Interface (CLI) or AWS Tools for Windows PowerShell. Download an AWS SDK if you are using a programming language supported by AWS.

Creating an Amazon S3 Bucket

First, create an Amazon S3 bucket to store the content that will be distributed by CloudFront.

To create an Amazon S3 bucket, sign in to the AWS Management Console and open the Amazon S3 console:

  1. Sign in to the AWS Management Console.
  1. Open the Amazon S3 console at Amazon S3 Console.
  1. Select Create bucket and enter a unique name that complies with naming rules.
  2. Select an AWS Region close to you.
  3. Keep the defaults for other settings and create the bucket.

Uploading Content to Your Bucket

Next, upload the content that you want to serve via CloudFront to your S3 bucket:

  1. Download the “hello world” webpage sample: hello-world-html.zip.
  2. Unzip the file and save the css folder and index.html.
  1. In the S3 console, select your bucket and choose Upload.
  2. Drag the css folder and index.html into the upload area and confirm the upload.

Creating a CloudFront Distribution

Now, you need to create a CloudFront distribution to serve the content from your S3 bucket. In this example, the distribution uses an Amazon S3 origin with Origin Access Control (OAC):

  1. Open the CloudFront console.
  1. Select Create distribution and select your S3 bucket as the origin domain.
  2. Enable OAC by selecting Origin access control settings under Origin Origin access.

4. Create a new OAC with default settings.

  1. Update the S3 Bucket policy by copying the bucket policy from the CloudFront console.
  2. Select Edit next to Bucket policy and apply the policy in the S3 console under S3 bucket permissions.
  1. Select Save changes to confirm.

Here’s an example policy:


  "Version": "2012-10-17",

  "Statement": [


      "Effect": "Allow",

      "Principal": {

        "Service": "cloudfront.amazonaws.com"


      "Action": "s3:GetObject",

      "Resource": "arn:aws:s3:::example-bucket-name/*",        

      "Condition": {

        "StringEquals": {

          "AWS:SourceArn": "arn:aws:cloudfront::123456789012:distribution/EDFDVBD6EXAMPLE"






Accessing Content via CloudFront

Finally,  you can access the content through your CloudFront distribution:

  1. Record the domain name of your CloudFront distribution (e.g., d121698abdecf8.cloudfront.net).
  2. Combine the CloudFront domain name with the path to your main page (e.g., /index.html). For example:
curl https://d121698abdecf8.cloudfront.net/index.html
  1. Upload new content to your S3 bucket and access it via CloudFront using the appropriate URL, for example:
aws s3 cp new-page.html s3://example-bucket-name/
curl https://d121698abdecf8.cloudfront.net/new-page.html

Or you can simply access this url via your browser.

CloudFront with Coralogix

Coralogix sets itself apart in observability with its modern architecture, enabling real-time insights into logs, metrics, and traces with built-in cost optimization. With out-of-the-box dashboards and alerts for CloudFront and WAF, you can hit the ground running with full visibility into operational and security issues. Coralogix’s straightforward pricing covers all its platform offerings including APM, RUM, SIEM, infrastructure monitoring and much more. With unparalleled support that features less than 1 minute response times and 1 hour resolution times, Coralogix is a leading choice for thousands of organizations across the globe.

Learn about the Coralogix WAF and CDN solution

Where Modern Observability
and Financial Savvy Meet.