AWS CloudFront is a web service that accelerates the delivery of your static and dynamic web content such as .js, .css, .html, and image files, and also audio, video, media files, to your users. It distributes your content by using a global network of data hubs called edge locations.
A CDN (Content Delivery Network) is a globally distributed network of caching servers that speed up the downloading of web pages and other content. CloudFront uses DNS (Domain Name System) geo-location to determine the geographic location of each request for web pages. Then it serves the web pages from edge caching servers (closest to that requested location) instead of the original web server. There are three core concepts that you need to understand in order to start using it:
With these concepts, you can easily use it to speed up the delivery of static content from your websites.
To use Amazon CloudFront, you start by creating a distribution, which is identified by a DNS domain name such as e1111111abcdef8.cloudfront.net. To serve files from amazon CloudFront, you can simply use the distribution domain name in place of your website’s domain name; the rest of the file paths stay unchanged. You can use the Amazon CloudFront distribution domain name as it is or you can create a user-friendly DNS name in your own domain by creating a CNAME record in Amazon Route 53 or any other DNS service. The CNAME is automatically redirected to your CloudFront distribution name.
When you generate a distribution you must define the DNS domain name of the origin of the Amazon S3 bucket or HTTP server from which you want Amazon CloudFront to get the definitive version of your object.
→ Amazon S3 bucket: myawsbucket.s3.amazonaws.com
→ Amazon Ec2 instance: ec2-22.214.171.124.compute-1.amazonaws.com
→ Elastic Load Balancing load balancer: my-load-balancer-9876543210.us-west-2.elb.amazonaws.com
→ Website URL: mywebserver.mycompanydomain.com
Once requested and served from an edge location, objects stay in the cache until they expire or are evicted to make room from more frequently requested content. The objects expire from the cache after 24 hours, by default. Once an object expires, the next request results in Amazon CloudFront forwarding the request to the origin to verify that the object is unchanged or to fetch a new version if it has been changed. Optionally, you can control how long objects stay in Amazon CloudFront cache before expiring. To do this, you can choose to use Cache-Control headers set by your origin server or you can set the minimum, maximum and default Time to Live (TTL) for objects in your Amazon CloudFront distribution. You can also eliminate copies of an object from all Amazon CloudFront edge locations at any moment by using the invalidation Application Program Interface (API). This feature removes the object from every Amazon CloudFront edge location regardless of the expiration of the period you set for that object on your origin server.