AWS — CloudFront
What is CloudFront?
CDN service that delivers content with low latency globally.
Create distribution
aws cloudfront create-distribution \
--origin-domain-name mybucket.s3.amazonaws.com \
--default-root-object index.html
S3 + CloudFront
# Create OAI
aws cloudfront create-origin-access-identity \
--cloud-origin-access-identity-config CallerReference=my-oai
# Update bucket policy
aws s3api put-bucket-policy \
--bucket mybucket \
--policy file://policy.json
Invalidation
aws cloudfront create-invalidation \
--distribution-id E1234567890ABC \
--paths "/*"
Price classes
| Class | Coverage |
|---|---|
| PriceClass_All | All edge locations |
| PriceClass_200 | US, Europe, Asia |
| PriceClass_100 | US, Europe only |
Custom domains
aws cloudfront create-distribution \
--origin-domain-name mybucket.s3.amazonaws.com \
--aliases Items=mydomain.com Quantity=1 \
--viewer-certificate ACMCertificateArn=arn:aws:acm:...
Behaviors
aws cloudfront create-distribution \
--default-cache-behavior \
ForwardedValues={QueryStrings=false,Cookies={Forward=none}}, \
ViewerProtocolPolicy=redirect-to-https, \
MinTTL=86400
Best practices
- Use HTTPS
- Enable compression
- Set appropriate cache policies
- Use invalidation wisely
Mini Practice
- Create a CloudFront distribution
- Connect to S3
- Set up custom domain
- Configure caching
Up Next
Continue with Route 53 - DNS Management.
Related Topics
Frequently Asked Questions about CloudFront
What is CloudFront in AWS?
CloudFront is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn CloudFront?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn CloudFront.
Why is CloudFront important in AWS?
CloudFront is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.