Skip to main content
CloudFront and Edge Computing Architecture

Module Overview

Estimated Time: 3-4 hours | Difficulty: Intermediate | Prerequisites: Networking, Storage
Edge services bring your content and compute closer to users worldwide. Think of it like franchise restaurants: instead of every customer driving to the headquarters kitchen, you open locations in every neighborhood. The food (your content) is prepared once and served locally. This module covers content delivery, global acceleration, and edge computing patterns — the difference between a 200ms page load and a 20ms one. What You’ll Learn:
  • CloudFront CDN configuration and optimization
  • Origin types and behaviors
  • Cache invalidation strategies
  • Lambda@Edge and CloudFront Functions
  • Global Accelerator for non-HTTP workloads
  • Edge security with WAF and Shield

CloudFront Overview

Amazon CloudFront is a global CDN with 450+ edge locations worldwide.

CloudFront Distribution Setup

Origin Types

CloudFront with Terraform


Cache Optimization

Cache Key Design

Cache Invalidation


Edge Computing

Lambda@Edge vs CloudFront Functions

CloudFront Function Example

Lambda@Edge Example


Global Accelerator

For non-HTTP workloads or when you need static IPs. The key mental model: CloudFront is a content-aware CDN (it understands HTTP, can cache, and run code at the edge), while Global Accelerator is a network-layer proxy (it simply routes TCP/UDP packets over the AWS backbone instead of the public internet, reducing jitter and packet loss).

Edge Security

WAF Integration


🎯 Interview Questions

Strategies:
  1. Normalize cache key:
    • Remove unnecessary query strings
    • Normalize header values
    • Don’t include cookies for static content
  2. Use versioned URLs:
    • /js/app.v2.3.1.js instead of /js/app.js?v=2.3.1
    • Allows long TTL without invalidation
  3. Configure appropriate TTLs:
    • Static assets: 1 year
    • HTML: 1 hour to 1 day
    • API: 0 or short TTL
  4. Use Origin Shield:
    • Additional caching layer
    • Reduces origin requests
  5. Monitor metrics:
    • Cache hit ratio in CloudWatch
    • Analyze popular request reports
Use Global Accelerator when:
  • TCP/UDP traffic (not HTTP)
  • Gaming, IoT, VoIP applications
  • Need static anycast IPs
  • Need instant failover between regions
  • No caching needed
Use CloudFront when:
  • HTTP/HTTPS traffic
  • Need content caching
  • Edge compute (Lambda@Edge)
  • Static website hosting
Use both together:
  • CloudFront for web traffic
  • Global Accelerator for WebSocket/gaming
Security layers:
  1. HTTPS only: Redirect HTTP to HTTPS
  2. Origin Access Control: S3 only accessible via CloudFront
  3. Signed URLs/Cookies: Restrict access to authenticated users
  4. WAF: Block common attacks, rate limiting
  5. Shield: DDoS protection (Standard free, Advanced paid)
  6. Field-Level Encryption: Encrypt sensitive form data
  7. Geo-restrictions: Block/allow by country
CloudFront Functions:
  • Simple, sub-millisecond operations
  • URL rewrites, header manipulation
  • Cost-effective at high scale
  • No network access needed
Lambda@Edge:
  • Complex logic, >1ms execution
  • Need to access external services
  • Image processing, personalization
  • Request body access needed
Cost example at 1B requests/month:
  • CloudFront Functions: ~$100
  • Lambda@Edge: ~$600+
Best practices:
  1. Avoid invalidation: Use versioned URLs
  2. Invalidate smartly:
    • Specific paths, not wildcards
    • Batch invalidations
    • First 1000/month free
  3. Short TTL for dynamic content:
    • Let cache expire naturally
    • Use Cache-Control headers
  4. Origin Shield:
    • Single point to invalidate
    • Reduces invalidation spread time

🧪 Hands-On Lab: Deploy Static Site with CloudFront

1

Create S3 Bucket

Private bucket with static website files
2

Create CloudFront Distribution

S3 origin with Origin Access Control
3

Configure Custom Domain

ACM certificate in us-east-1, Route 53 alias
4

Add CloudFront Function

URL rewrite for SPA routing
5

Enable WAF

AWS managed rules + rate limiting
6

Monitor Performance

CloudWatch metrics, cache hit ratio

Next Module

Messaging & Integration

Master SQS, SNS, EventBridge, and event-driven architectures