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:
| Pattern | Origin | TTL | Use Case |
|---|---|---|---|
/static/* | S3 | 1 year | Assets with cache-busting |
/api/* | API Gateway | 0 | Dynamic API calls |
*.jpg | S3 | 1 week | Image assets |
| Default | EC2 | 1 hour | Dynamic 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
- Use versioned assets: Include hashes in filenames instead of invalidating
- Set appropriate TTLs: Balance freshness with cache efficiency
- Enable compression: Gzip/Brotli compression for text-based content
- Configure error pages: Custom error responses for better UX