GenAIHub
← Back to Technical Section

Amazon CloudFront

A fast, secure, and programmable Content Delivery Network (CDN) from AWS for global content distribution.

What is Amazon CloudFront?

Amazon CloudFront is a highly scalable and secure Content Delivery Network (CDN) service provided by AWS. It accelerates the delivery of static and dynamic web content—such as HTML, CSS, JavaScript, images, videos, APIs, and applications—to users worldwide by caching content at edge locations close to your audience. CloudFront integrates seamlessly with other AWS services like Amazon S3, EC2, Elastic Load Balancing, and Lambda@Edge, enabling developers to build robust, low-latency, and secure web applications.

CloudFront offers programmable edge computing, DDoS protection, SSL/TLS encryption, and customizable caching strategies. It is designed to handle high traffic loads, reduce latency, and optimize content delivery for both static and dynamic assets. With a global network of edge locations, CloudFront ensures fast, reliable, and secure user experiences regardless of geographic location.

Architecture

Users Origin Servers (S3, EC2, etc.) Edge Locations CloudFront Distribution

Key Components

Edge Locations

Globally distributed data centers where CloudFront caches copies of your content, reducing latency by serving requests closer to users.

Distributions

Configurations that define how CloudFront delivers content from one or more origins (such as S3 buckets, EC2 instances, or custom servers) to viewers.

Origin Servers

The backend sources of content, such as Amazon S3, EC2, or on-premises servers, from which CloudFront fetches data not already cached at the edge.

Key Capabilities

Low Latency Content Delivery

Delivers content to users with minimal delay by caching at edge locations worldwide.

Security & DDoS Protection

Integrated with AWS Shield and AWS WAF for robust security, SSL/TLS encryption, and protection against DDoS attacks.

Programmable Edge (Lambda@Edge)

Run custom code at edge locations to personalize content, rewrite URLs, or implement advanced authentication and authorization logic.

Common Use Cases

Static Website Hosting
API Acceleration
Video Streaming
Dynamic Content Delivery
Software Distribution
Global Application Load Balancing

Implementation Example

# Terraform Example: Create a CloudFront Distribution for an S3 Bucket

resource "aws_s3_bucket" "static_site" {
  bucket = "my-static-site-bucket"
  acl    = "public-read"
}

resource "aws_cloudfront_distribution" "s3_distribution" {
  origin {
    domain_name = aws_s3_bucket.static_site.bucket_regional_domain_name
    origin_id   = "s3-origin"
  }

  enabled             = true
  is_ipv6_enabled     = true
  default_root_object = "index.html"

  default_cache_behavior {
    allowed_methods  = ["GET", "HEAD"]
    cached_methods   = ["GET", "HEAD"]
    target_origin_id = "s3-origin"

    forwarded_values {
      query_string = false
      cookies {
        forward = "none"
      }
    }
  }

  price_class = "PriceClass_100"
  viewer_certificate {
    cloudfront_default_certificate = true
  }
}
                

This Terraform example provisions an S3 bucket and a CloudFront distribution that serves content from the bucket. It configures caching, enables IPv6, and uses the default CloudFront SSL certificate for HTTPS delivery.

Related Topics

Test Your Knowledge

Score 8/10 or higher to pass