Amazon CloudFront
Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency and high transfer speeds. It integrates with other AWS services to give developers and businesses an easy way to distribute content to end users with high performance and security.
How CloudFront Works
- Origin Server: This is where your original content is stored. It can be an Amazon S3 bucket, an EC2 instance, an Elastic Load Balancer, or any custom HTTP server (on-premises or another cloud).
- Edge Locations (Points of Presence - PoPs): CloudFront has a global network of hundreds of PoPs. When a user requests content that you're serving with CloudFront, the request is routed to the nearest edge location.
- Caching: If the content is already at the edge location, CloudFront delivers it immediately. If not, CloudFront retrieves it from your origin server, caches it at the edge, and then delivers it to the user. Subsequent requests for the same content from nearby users are served directly from the cache.
- Optimized Routing: CloudFront uses the AWS global network backbone, which is highly optimized, to route requests from edge locations to your origin server. This often provides faster and more reliable connections than the public internet.
Key Features
- Global Network: Hundreds of edge locations worldwide for low-latency delivery.
- Caching: Reduces load on origin servers and speeds up content delivery.
- Security:
- AWS WAF Integration: Protects against common web exploits.
- AWS Shield Integration: Provides Distributed Denial of Service (DDoS) protection.
- HTTPS Support: Encrypts data in transit.
- Field-Level Encryption: Encrypts specific data fields at the edge.
- Geo-Restriction: Control who can access your content based on geographic location.
- Signed URLs/Cookies: Grant temporary access to private content.
- Customization & Edge Compute:
- Lambda@Edge: Run serverless code at CloudFront edge locations in response to CloudFront events (viewer request, origin request, origin response, viewer response).
- CloudFront Functions: Lightweight JavaScript functions for high-scale, latency-sensitive CDN customizations (e.g., URL rewrites, header manipulation).
- Origin Shield: An additional caching layer between your edge locations and your origin, further reducing origin load.
- Real-time Logs: Get detailed information about viewer requests.
- Integration with AWS Services: Seamlessly works with S3, EC2, ELB, Route 53, WAF, Shield, and Lambda.
DDoS protection refers to the measures and services designed to defend against Distributed Denial of Service (DDoS) attacks. A DDoS attack is a malicious attempt to disrupt the normal traffic of a targeted server, service, or network by overwhelming it with a flood of internet traffic from multiple compromised computer systems.
Use Cases
- Website Acceleration: Deliver static and dynamic website content (HTML, CSS, JavaScript, images) faster to global users.
- Video Streaming: Distribute on-demand and live video content with high performance and scalability.
- API Acceleration: Improve the performance and reduce latency for API calls by caching API responses at the edge.
- Software Distribution: Deliver software updates and installation packages quickly and reliably.
- Security Enhancement: Protect web applications and APIs from Distributed Denial of Service (DDoS) attacks and other web exploits using WAF and Shield.
- Edge Logic: Perform custom logic at the edge, such as A/B testing, user authentication, URL rewrites, or header manipulation, without impacting origin performance.
- Private Content Delivery: Securely deliver private content (e.g., paid subscriptions, internal documents) using signed URLs or cookies.
Example: Accelerating a Static Website Hosted on S3
- Upload Content: Store your static website files (HTML, CSS, JS, images) in an Amazon S3 bucket.
- Create a CloudFront Distribution:
- Specify your S3 bucket as the Origin Domain Name.
- Configure Cache Behaviors (e.g., cache duration for different file types).
- Enable HTTPS for secure delivery.
- Optionally, configure an Origin Access Control (OAC) to restrict direct S3 bucket access, ensuring all traffic goes through CloudFront.
- Update DNS: Point your domain's CNAME record to the CloudFront distribution's domain name (e.g.,
d12345.cloudfront.net). - User Access: When a user visits your website, their request is routed to the nearest CloudFront edge location, which serves the content from its cache or fetches it from S3 via the optimized AWS network.
