CloudFront
What is CloudFront
CloudFront is a content delivery network (CDN).
A CDN is a system of distributed servers (network) that deliver webpages and other web content to a user, based on the geographic locations of the user, the origin of the webpage, and a content delivery server.
Key Terminology
Edge Location
Location where content will be cached. This is separate to an AWS Region/AZ
Origin
The origin of all the files that the CDN will distribute. This can be an S3 Bucket, an EC2 instance, an Elastic Load Balancer or Route53.
Distribution
This is the name given to the CDN, which consists of a collection of Edge Locations.
Type of Distributions
Web Distribution - Typically used for Websites.
RTMP - Used for Media Streaming
Edge locations are not just READ only - you can write to them too.
Objects are cached for the life of the TTL (Time To Live)
You can clear cached objects (invalidate), but you will be charged.
CloudFront is a Global Service
Create CloudFront Distribution
- Select Networking & Content Delivery > CloudFront - Create Distribution > Web
Origin Domain Name | List of available origins including S3, ELB ect |
Origin Path | If you have a folder path inside your S3 bucket that you want to target |
Minimum, Maximum and Default TTL | Specifies the Time to Live (cached) for your objects in their edge locations |
Restrict Viewer Access | Ensure that users have to use signed url's or signed cookies to access content in CloudFront |
AWS WAF Web ACL | You can add Web Applicaion Firewalls infront of your CloudFront distrubution |
Lambda@Edge
Lambda@Edge lets you run Lambda functions to customize the content that CloudFront delivers, executing the functions in AWS locations closer to the viewer.
The functions run in response to CloudFront events, without provisioning or managing servers.
You can use Lambda functions to change CloudFront requests and responses at the following points:
- After CloudFront receives a request from a viewer (viewer request)
- Before CloudFront forwards the request to the origin (origin request)
- After CloudFront receives the response from the origin (origin response)
- Before CloudFront forwards the response to the viewer (viewer response)
Origin Failover
You can set up an origin failover by creating an origin group with two origins with one as the primary origin and the other as the second origin which CloudFront automatically switches to when the primary origin fails.