AWS - CloudFront
CloudFront allows you to create distributions. You can imagine that distribution is a server that caches and delivers content from another server behind the distribution. The server behind distribution is called origin, location where the original version of your content is stored.
# Origin: http://example.com/images/image.jpg # Distribution: http://d111111abcdef8.cloudfront.net/images/image.jpg
CloudFront increases content download speed world wide. You can choose to have distribution endpoints in all major geographical areas EU, US, Asia etc.
Distributions can additionally:
- we given custom domain e.g. cdn.example.com
- require HTTPS
- keep access logs
- forward cookies or query strings to the origin
- limit access to specific user
- limit access by user country
There are two distribution types:
- Web Distribution: Downloadable media content like .html, .css, .png, .avi. Linked to S3, EC2 or custom HTTP/HTTPS server.
- RTMP Distribution: Streamable media content using Real-Time Media Protocol. Must be linked to a S3.
HTTP Server (Origin) http://example.com/images/image.jpg Internet (the first time file is requested) AWS CF (Distribution) http://d111111abcdef8.cloudfront.net/images/image.jpg Internet User
AWS S3 (Files) http://myawsbucket.s3.amazonaws.com/images/image.jpg Internet (the first time file is requested) AWS CF (Distribution) http://d222222abcdef8.cloudfront.net/images/image.jpg Internet User
To create a distribution:
- Go to AWS CloudFront Console > Distributions.
- Click Create Distribution.
- Define your origin.
- Other settings are optional e.g. distribution areas and logging.
- Start it and wait for it to be deployed.
- Use distribution Domain Name to serve the assets.
Distributions can also have multiple origins. You use paths to assign individual content to specific origin.
Origin 1: http://example.com Origin 2: http://company.com Distribution: http://d333333abcdef8.cloudfront.net Behaviour 3: Content beginning with /images/ are found in origin 2. Behaviour 2: Content matching *.jpg are found in origin 2. Behaviour 1: All the rest of the content is found in origin 1