Reading25 min read·Module 4

CloudFront for Data Transfer

Key concepts

  • CloudFront vs direct S3

  • Regional edge caches

  • Price classes

  • Origin Shield

  • Compression benefits

Overview

Amazon CloudFront is a global Content Delivery Network (CDN) that caches content at edge locations worldwide. Beyond performance benefits, CloudFront offers significant cost advantages for data transfer compared to serving content directly from origins like S3 or EC2. Understanding CloudFront pricing mechanisms, regional edge caches, Origin Shield, and price classes is essential for the SAA-C03 exam.

CloudFront Cost Advantage

CloudFront data transfer to the internet is significantly cheaper than S3 or EC2 direct delivery. For the first 10 TB/month, CloudFront charges $0.085/GB from US/Europe edge locations compared to $0.09/GB for S3 data transfer out. More importantly, data transfer from origins to CloudFront is FREE, and CloudFront caching reduces origin requests, compounding savings. For high-traffic workloads, CloudFront can reduce data transfer costs by 40-60%.

Exam Tip

When exam questions mention 'reduce data transfer costs for global users' or 'cost-effective content delivery,' CloudFront is typically the answer. Look for scenarios with high bandwidth, global audiences, or repeated content access. Also remember that Origin Shield can reduce origin fetches by up to 90%, providing significant cost savings for multi-region architectures.

Key Concepts

CloudFront vs Direct S3 Delivery Costs

CloudFront vs S3 direct delivery cost comparison
Figure 1: CloudFront vs Direct S3 Data Transfer Costs

S3 Direct Delivery Pricing

S3 Data Transfer Out to Internet (us-east-1) | Volume/Month | Cost per GB | |--------------|-------------| | First 10 TB | $0.09 | | Next 40 TB | $0.085 | | Next 100 TB | $0.07 | | Over 150 TB | $0.05 |

Key Characteristics:

  • Every request fetches from S3 origin
  • No caching benefit
  • No edge location optimization
  • Full data transfer for each request
  • Cross-region requests add latency

Example: 50 TB/month S3 Direct:

First 10 TB: 10,000 GB × $0.09 = $900
Next 40 TB: 40,000 GB × $0.085 = $3,400
Total: $4,300/month

CloudFront Delivery Pricing

CloudFront Data Transfer to Internet | Region | First 10 TB | Next 40 TB | Next 100 TB | |--------|-------------|------------|-------------| | United States, Europe | $0.085/GB | $0.080/GB | $0.060/GB | | South America | $0.110/GB | $0.105/GB | $0.090/GB | | Australia, Asia Pacific | $0.114/GB | $0.089/GB | $0.086/GB | | India | $0.109/GB | $0.085/GB | $0.082/GB |

Key Cost Benefits:

  • Data transfer from origin to CloudFront: FREE
  • Caching reduces origin requests dramatically
  • Lower per-GB rate than S3 direct for most regions
  • Volume discounts more aggressive
  • HTTP/HTTPS requests are additional but minimal

Example: 50 TB/month via CloudFront (US/Europe):

First 10 TB: 10,000 GB × $0.085 = $850
Next 40 TB: 40,000 GB × $0.080 = $3,200
Total: $4,050/month

Savings vs S3 Direct: $250/month (5.8%)

With 80% Cache Hit Rate:

CloudFront edge delivery: $4,050
Origin fetches: 20% × 50 TB = 10 TB (FREE to CloudFront)
S3 requests: negligible
Effective origin data: 10 TB vs 50 TB

Origin load reduced by 80%

Total Cost of Ownership Comparison

Comprehensive Cost Analysis: S3 Direct vs CloudFront

Scenario: 100 TB/month static content delivery globally

| Cost Component | S3 Direct | CloudFront (80% cache) | |----------------|-----------|------------------------| | Data Transfer Out | $7,700 | $6,200 | | Origin Data Transfer | N/A | $0 (free to CF) | | Request Costs | $500 | $200 | | Origin Requests | 100% | 20% | | Total Monthly | $8,200 | $6,400 | | Annual Savings | - | $21,600 |

Additional CloudFront Benefits Not Reflected in Cost:

  • 50-70% latency reduction globally
  • DDoS protection via AWS Shield Standard (included)
  • SSL/TLS at no additional cost
  • Field-level encryption capability
  • Real-time logging and analytics

Regional Edge Caches and Origin Shield

CloudFront edge location hierarchy
Figure 2: CloudFront Edge Location Architecture

CloudFront Edge Location Hierarchy

Three-Tier Caching Architecture

1. Edge Locations (450+ worldwide)

  • Closest to end users
  • First cache layer checked
  • Smallest cache capacity
  • Most numerous locations
  • TTL-based eviction

2. Regional Edge Caches (13 locations)

  • Located between edge and origin
  • Larger cache capacity
  • Serve multiple edge locations
  • Reduce origin fetches
  • Automatically included (no extra cost)

3. Origin Shield (optional)

  • Single additional caching layer
  • Positioned in front of origin
  • Centralizes origin requests
  • Reduces origin load by up to 90%
  • Separate per-request charge

Request Flow Without Origin Shield:

User → Edge Location → Regional Edge Cache → Origin
       (cache miss)     (cache miss)

Multiple edge locations can simultaneously request from origin

Request Flow With Origin Shield:

User → Edge Location → Regional Edge Cache → Origin Shield → Origin
       (cache miss)     (cache miss)          (single request)

All cache misses funnel through Origin Shield first

Origin Shield for Cost Reduction

Origin Shield: Reduce Origin Load and Costs

How Origin Shield Works:

  • Acts as additional caching layer in front of origin
  • Collapses multiple simultaneous requests into one
  • Maintains cache even when edge caches evict content
  • Reduces origin fetch frequency dramatically

Origin Shield Pricing (varies by region): | Shield Region | Price per 10,000 Requests | |---------------|---------------------------| | US East (N. Virginia) | $0.0090 | | Europe (Frankfurt) | $0.0090 | | Asia Pacific (Tokyo) | $0.0120 | | Asia Pacific (Mumbai) | $0.0090 |

Cost Savings Calculation:

  • Typical origin request reduction: 70-90%
  • If origin is EC2/ALB: reduces compute load
  • If origin is S3: reduces request costs
  • If origin is third-party: reduces external data transfer

Example: 1 billion requests/month with 40% cache miss rate

Without Origin Shield:
- Origin requests: 400 million
- Origin data transfer: High

With Origin Shield (90% reduction):
- Origin Shield requests: 400 million
- Actual origin requests: 40 million
- Origin Shield cost: 400M / 10,000 × $0.009 = $360/month
- Origin request reduction: 360 million requests

When to Use Origin Shield

Origin Shield Use Cases and ROI

Recommended Scenarios:

  1. Multi-region viewers: Global audience hitting different edge caches
  2. High-traffic events: Product launches, live streaming
  3. Expensive origins: Lambda@Edge, API Gateway, or external APIs
  4. Low cache hit ratio content: Personalized or long-tail content
  5. Origin capacity protection: Prevent origin overload during traffic spikes

Origin Shield ROI Calculation: | Metric | Without Shield | With Shield | Savings | |--------|----------------|-------------|---------| | Origin requests/month | 10 million | 1 million | 90% | | Origin compute cost | $500 | $50 | $450 | | Origin data transfer | $900 | $90 | $810 | | Origin Shield cost | $0 | $9 | -$9 | | Net Monthly Savings | - | - | $1,251 |

When NOT to Use Origin Shield:

  • Single-region viewer base
  • Very high cache hit rates (>95%)
  • Low request volume (cost may exceed benefit)
  • Origin is already highly scalable and cheap

CloudFront Price Classes

CloudFront Price Classes Map
Figure 3: CloudFront Price Classes Geographic Coverage

Price Class Options

CloudFront Price Classes: Cost vs Coverage Trade-off

Price Class All (Default)

  • Uses all 450+ edge locations globally
  • Best performance worldwide
  • Highest cost per GB (varies by region)
  • Recommended for: Global audiences, performance-critical apps

Price Class 200

  • Excludes: South America, Australia/New Zealand
  • Uses: North America, Europe, Asia, Africa, Middle East
  • Lower cost than Price Class All
  • Recommended for: Most global businesses without SA/AU traffic

Price Class 100

  • Uses: North America, Europe only
  • Lowest cost option
  • Recommended for: US/EU-focused applications, cost optimization

Pricing Impact by Edge Region: | Region | Price Class All | Price Class 200 | Price Class 100 | |--------|-----------------|-----------------|-----------------| | North America | $0.085/GB | $0.085/GB | $0.085/GB | | Europe | $0.085/GB | $0.085/GB | $0.085/GB | | Asia Pacific | $0.114/GB | $0.114/GB | N/A | | South America | $0.110/GB | N/A | N/A | | Australia | $0.114/GB | N/A | N/A |

Price Class Selection Strategy

Choosing the Right Price Class

Decision Framework:

Is your audience primarily in North America and Europe?
├── Yes → Price Class 100 (lowest cost)
└── No → Do you have significant traffic from South America or Australia?
    ├── Yes → Price Class All (full coverage)
    └── No → Price Class 200 (balanced)

Important Consideration:

  • Viewers in excluded regions are NOT blocked
  • They are served from the nearest available edge location
  • This may result in higher latency, not failure
  • Actual cost savings depend on traffic distribution

Example Cost Savings: Scenario: 100 TB/month, 70% US/EU, 20% Asia, 10% South America

| Price Class | Monthly Cost | Latency Impact | |-------------|--------------|----------------| | All | $8,850 | Optimal globally | | 200 | $8,350 | +50-100ms SA only | | 100 | $7,550 | +20-50ms Asia, +100ms SA |

Recommendation: Start with Price Class 100 or 200, monitor CloudWatch latency metrics, upgrade if user experience suffers.

Compression Benefits

CloudFront Compression for Cost Reduction

Automatic Compression: Reduce Transfer Costs

Supported Compression Methods:

  • Gzip: Widely supported, good compression
  • Brotli: Better compression, modern browser support

Enabling Compression:

  • Automatic when viewer supports it (Accept-Encoding header)
  • Works for compressible content types (text, JSON, JavaScript, CSS)
  • Does NOT compress already compressed formats (images, videos, zip)

Compression Impact on Costs: | Content Type | Uncompressed | Gzip | Brotli | Savings | |--------------|--------------|------|--------|---------| | HTML | 100 KB | 25 KB | 20 KB | 75-80% | | JavaScript | 500 KB | 150 KB | 120 KB | 70-76% | | CSS | 200 KB | 50 KB | 40 KB | 75-80% | | JSON API | 1 MB | 200 KB | 150 KB | 80-85% |

Monthly Cost Impact:

Scenario: 10 TB of compressible content

Without compression:
- Data transfer: 10 TB × $0.085 = $850

With Gzip (75% reduction):
- Data transfer: 2.5 TB × $0.085 = $212.50

Monthly Savings: $637.50 (75%)

Configuration Requirements:

  1. Enable "Compress objects automatically" in cache behavior
  2. Ensure origin sends correct Content-Type headers
  3. Origin should NOT compress (let CloudFront handle it)
  4. Set appropriate Cache-Control headers

CLI Commands

SHCreate CloudFront Distribution with S3 Origin
# Create a CloudFront distribution with S3 origin
aws cloudfront create-distribution \
  --distribution-config '{
    "CallerReference": "my-distribution-2024",
    "Origins": {
      "Quantity": 1,
      "Items": [{
        "Id": "S3-mybucket",
        "DomainName": "mybucket.s3.amazonaws.com",
        "S3OriginConfig": {
          "OriginAccessIdentity": ""
        }
      }]
    },
    "DefaultCacheBehavior": {
      "TargetOriginId": "S3-mybucket",
      "ViewerProtocolPolicy": "redirect-to-https",
      "CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
      "Compress": true
    },
    "PriceClass": "PriceClass_100",
    "Enabled": true
  }'
SHEnable Origin Shield
# Update distribution to enable Origin Shield
aws cloudfront update-distribution \
  --id E1234567890ABC \
  --distribution-config '{
    "Origins": {
      "Items": [{
        "Id": "S3-mybucket",
        "DomainName": "mybucket.s3.amazonaws.com",
        "OriginShield": {
          "Enabled": true,
          "OriginShieldRegion": "us-east-1"
        }
      }]
    }
  }'

# Verify Origin Shield is enabled
aws cloudfront get-distribution \
  --id E1234567890ABC \
  --query 'Distribution.DistributionConfig.Origins.Items[*].OriginShield'
SHUpdate Price Class for Cost Optimization
# Get current distribution config
aws cloudfront get-distribution-config --id E1234567890ABC > config.json

# Change PriceClass to PriceClass_100 for lowest cost
# Edit config.json: "PriceClass": "PriceClass_100"

# Update distribution with new price class
aws cloudfront update-distribution \
  --id E1234567890ABC \
  --distribution-config file://config.json \
  --if-match ETAG_FROM_GET

# Verify price class change
aws cloudfront get-distribution \
  --id E1234567890ABC \
  --query 'Distribution.DistributionConfig.PriceClass'
SHMonitor Cache Hit Ratio and Costs
# Get cache hit ratio metrics
aws cloudwatch get-metric-statistics \
  --namespace AWS/CloudFront \
  --metric-name CacheHitRate \
  --dimensions Name=DistributionId,Value=E1234567890ABC Name=Region,Value=Global \
  --start-time $(date -u -d "7 days ago" +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 86400 \
  --statistics Average

# Get bytes downloaded (for cost estimation)
aws cloudwatch get-metric-statistics \
  --namespace AWS/CloudFront \
  --metric-name BytesDownloaded \
  --dimensions Name=DistributionId,Value=E1234567890ABC Name=Region,Value=Global \
  --start-time $(date -u -d "30 days ago" +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 2592000 \
  --statistics Sum

# Get origin requests (to evaluate Origin Shield need)
aws cloudwatch get-metric-statistics \
  --namespace AWS/CloudFront \
  --metric-name OriginRequests \
  --dimensions Name=DistributionId,Value=E1234567890ABC Name=Region,Value=Global \
  --start-time $(date -u -d "30 days ago" +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 2592000 \
  --statistics Sum

Best Practices

  1. Always Use CloudFront for High-Traffic Static Content: CloudFront pricing is more favorable than S3 direct delivery, and caching reduces origin load significantly

  2. Enable Origin Shield for Multi-Region Audiences: The small per-request cost is offset by dramatic origin request reduction

  3. Choose Appropriate Price Class: Start with Price Class 100 or 200 if audience is primarily US/Europe, upgrade only if latency metrics warrant

  4. Enable Automatic Compression: Configure CloudFront to compress text-based content—this can reduce transfer costs by 70-80%

  5. Set Optimal TTLs: Longer TTLs increase cache hit ratio, reducing origin fetches and costs

  6. Use Cache-Control Headers: Configure origins to send appropriate headers for CloudFront to cache effectively

  7. Monitor Cache Hit Ratio: Target >80% hit ratio; investigate if lower—may indicate TTL issues or cache key problems

  8. Consolidate Distributions: Multiple distributions increase management overhead; use behaviors to route requests within single distribution

Common Exam Scenarios

CloudFront Cost Optimization Scenarios

ScenarioRecommended SolutionKey Reasoning
Global static website with high S3 costsAdd CloudFront with caching enabledCloudFront egress cheaper than S3, caching reduces origin requests
Video streaming to global audienceCloudFront with Origin Shield + Price Class AllHigh bandwidth benefits from edge caching and global coverage
API with mostly US/EU users, high origin costsCloudFront with Origin Shield + Price Class 100Reduces origin load while minimizing edge costs
Large text-based content deliveryEnable CloudFront compression75-80% transfer cost reduction for compressible content
Multi-region application hitting origin from many edgesEnable Origin Shield in region closest to originCollapses requests, reduces origin fetches by up to 90%
Cost-sensitive app with limited Asia trafficPrice Class 200 instead of AllExcludes expensive SA/AU edges while covering most users
High-volume downloads with many unique filesIncrease TTL values, enable Origin ShieldLong-tail content benefits from centralized caching
Real-time API with low cache potentialEvaluate if CloudFront adds value; consider direct originLow cache hit reduces CloudFront benefits

Additional Exam Scenarios

ScenarioSolutionReasoning
S3 website costs $5,000/month in data transferCloudFront distribution with cachingFree S3→CloudFront transfer + lower CloudFront egress rates
Application in us-east-1 serving Australia usersCloudFront with Price Class AllEnsures Australian edge locations are used for low latency
Startup wants to minimize costs, all users in USPrice Class 100 + compressionLowest cost edges + reduced data transfer via compression
Media company with 10 TB daily downloadsCloudFront with long TTLs (1 week+)High cache hit ratio minimizes origin fetches
E-commerce site with traffic spikes during salesOrigin Shield to protect originPrevents origin overload during high-traffic events
SaaS with 50% EU, 50% Asia usersPrice Class 200Good coverage for both regions without expensive SA/AU edges

Common Pitfalls

Serving S3 Content Directly Without CloudFront

Many organizations serve high-traffic S3 content directly without CloudFront, paying full S3 egress rates ($0.09/GB) for every request. CloudFront not only offers lower per-GB pricing ($0.085/GB for US/EU) but caches content at edge locations, dramatically reducing the number of origin fetches. For content accessed multiple times, CloudFront can reduce effective data transfer costs by 50-80%.

Using Price Class All When Unnecessary

Price Class All uses expensive edge locations in South America ($0.110/GB) and Australia ($0.114/GB) even if you have minimal traffic from those regions. If your audience is primarily in North America and Europe, using Price Class 100 can reduce costs with minimal latency impact for the few users in other regions. Always analyze your traffic distribution with CloudWatch before choosing price class.

Ignoring Origin Shield for High-Traffic Distributions

Without Origin Shield, cache misses from multiple edge locations can simultaneously hit your origin, multiplying origin costs and load. Origin Shield collapses these requests into a single origin fetch. For distributions with global traffic or expensive origins (Lambda@Edge, API Gateway, external APIs), the small per-request Origin Shield fee ($0.009/10K requests) is offset by 70-90% origin request reduction.

Not Enabling Compression for Text-Based Content

CloudFront can automatically compress text-based content (HTML, CSS, JavaScript, JSON) using Gzip or Brotli, reducing transfer size by 70-85%. Failing to enable compression means paying for 3-4x more data transfer than necessary. Enable "Compress objects automatically" in cache behavior settings for immediate savings on compressible content types.

Low Cache Hit Ratio Due to Poor TTL Configuration

Short TTLs or missing Cache-Control headers result in frequent origin fetches, negating CloudFront's caching benefits. Monitor your distribution's cache hit ratio in CloudWatch—target greater than 80%. If lower, investigate: are TTLs too short? Are query strings or headers unnecessarily included in cache key? Is content truly uncacheable? A 50% vs 90% cache hit ratio means 4x more origin requests.

Quick Reference

CloudFront Pricing (US/Europe Edge Locations)

ComponentCost
Data Transfer Out (first 10 TB)$0.085/GB
Data Transfer Out (next 40 TB)$0.080/GB
Data Transfer Out (next 100 TB)$0.060/GB
Data Transfer from OriginFREE
HTTPS Requests (10,000)$0.01
HTTP Requests (10,000)$0.0075
Origin Shield (10,000 requests)$0.0090

Price Class Coverage

Price ClassRegions IncludedBest For
AllAll 450+ edge locations globallyGlobal audience, performance-critical
200North America, Europe, Asia, Africa, Middle EastMost global apps, cost-conscious
100North America, Europe onlyUS/EU focused, maximum savings

Origin Shield Regions

Shield RegionPer 10K Requests
US East (N. Virginia)$0.0090
US West (Oregon)$0.0090
Europe (Frankfurt)$0.0090
Europe (London)$0.0090
Asia Pacific (Tokyo)$0.0120
Asia Pacific (Singapore)$0.0090

Compression Savings Reference

Content TypeTypical CompressionCost Impact
HTML75-80% smaller75-80% savings
JavaScript70-76% smaller70-76% savings
CSS75-80% smaller75-80% savings
JSON80-85% smaller80-85% savings
Images (JPEG, PNG)0% (already compressed)No change
Video (MP4)0% (already compressed)No change

Essential CLI Commands

# Create CloudFront distribution with compression enabled
aws cloudfront create-distribution \
  --origin-domain-name mybucket.s3.amazonaws.com \
  --default-root-object index.html

# Update distribution to use Price Class 100
aws cloudfront get-distribution-config --id E1234567890ABC > config.json
# Edit: "PriceClass": "PriceClass_100"
aws cloudfront update-distribution --id E1234567890ABC --distribution-config file://config.json

# Monitor cache hit ratio
aws cloudwatch get-metric-statistics \
  --namespace AWS/CloudFront \
  --metric-name CacheHitRate \
  --dimensions Name=DistributionId,Value=E1234567890ABC Name=Region,Value=Global \
  --start-time $(date -u -d "7 days ago" +%Y-%m-%dT%H:%M:%SZ) \
  --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
  --period 86400 \
  --statistics Average

# Invalidate cache (use sparingly - has cost)
aws cloudfront create-invalidation \
  --distribution-id E1234567890ABC \
  --paths "/*"

Test Your Knowledge

Q

A company serves 50 TB of static content monthly directly from S3 to global users. They want to reduce data transfer costs. What is the MOST cost-effective solution?

AEnable S3 Transfer Acceleration
BCreate a CloudFront distribution with S3 as origin
CUse S3 Cross-Region Replication to regions closer to users
DEnable S3 Intelligent-Tiering
Q

A media company uses CloudFront to deliver video content globally. They notice high origin request charges from their S3 bucket. The content is accessed from many different geographic regions. What should they enable to reduce origin costs?

APrice Class 100 to reduce edge location costs
BOrigin Shield in the region closest to the S3 bucket
CS3 Transfer Acceleration for faster origin fetches
DMultiple S3 origins across regions
Q

An e-commerce company uses CloudFront for their website serving primarily US and European customers, with less than 5% traffic from other regions. They currently use Price Class All. How can they reduce costs?

ASwitch to Price Class 100 for US/Europe only edge locations
BEnable Origin Shield to reduce origin requests
CDisable CloudFront and serve directly from the origin
DAdd more edge locations using Lambda@Edge
Q

A company serves large JSON API responses (averaging 2 MB each) through CloudFront. They transfer 20 TB monthly. How can they reduce data transfer costs most effectively?

AEnable automatic compression in CloudFront cache behavior
BUse Price Class 100 instead of Price Class All
CEnable Origin Shield to reduce origin fetches
DIncrease cache TTL to reduce origin requests

Further Reading

Related services

CloudFrontS3