Skip to main content

Amazon CloudFront

Amazon CloudFront is a global content delivery network (CDN) that accelerates delivery of websites, APIs, video content, and other web assets. With edge locations worldwide, CloudFront caches content closer to users for faster load times.

Key Features

  • Global edge network: 400+ points of presence worldwide
  • Origin flexibility: Serve content from S3, EC2, API Gateway, or any HTTP server
  • SSL/TLS: Free SSL certificates with AWS Certificate Manager
  • Lambda@Edge: Run code at edge locations for dynamic content

Common Use Cases

  • Static website hosting: Accelerate sites hosted on S3
  • API acceleration: Cache API responses globally
  • Video streaming: Deliver live and on-demand video
  • Dynamic content: Reduce latency for uncacheable content via persistent connections

Cache Behaviors

Configure different behaviors based on URL patterns:

PatternOriginTTLUse Case
/static/*S31 yearAssets with cache-busting
/api/*API Gateway0Dynamic API calls
*.jpgS31 weekImage assets
DefaultEC21 hourDynamic pages

What We Like

  • Performance: Dramatic latency improvements for global audiences
  • Security: Built-in DDoS protection, WAF integration, field-level encryption
  • Cost effective: Reduces load on origin servers, often cheaper than serving directly
  • Reliability: Automatic failover between edge locations

What We Don't Like

  • Cache invalidation: Can take time and costs money at scale
  • Debugging: Issues at edge locations can be hard to diagnose
  • Configuration complexity: Many options can be overwhelming

Best Practices

  1. Use versioned assets: Include hashes in filenames instead of invalidating
  2. Set appropriate TTLs: Balance freshness with cache efficiency
  3. Enable compression: Gzip/Brotli compression for text-based content
  4. Configure error pages: Custom error responses for better UX