What is it?
It’s a CDN for static and dynamic content. It replicates your content across AWS zones but also what they call edge locations which I just see as cached content closer to the end-user with the lowest latency it can grant you.
Do I use it currently?
Yes, I personally use it in production to front an S3 bucket we deploy a single-page-app into. This is pretty cheap to run but you need to know the gotchya's of using the CDN and Edge locations TTL (time to live or time it sticks around if the term isn’t familiar for you) to avoid situations where cached HTML pages are looking for assets that are no longer present because you’ve replaced them.
When you request an asset via Cloudfront, if the edge location has a copy of that asset, that is what you get 🎉 but if not it will ‘miss’ and go to the S3 ‘origin’.
When you need to get rid of the cache’s e.g. you just updated content, then you need to ‘invalidate’ it (for a charge).
A bucket located in London is being used by a lot of users in Australia what can you do to improve performance.
One might have been S3 replication but a good idea might be to set up a distribution via Cloudfront so that cached versions of that content are found closer to those users.
Creating a ‘distribution’?
- Make sure your user has a CloudFront policy to let them use it, I’m lazy and just used CloudfrontFullAccess.
- Go to https://console.aws.amazon.com/cloudfront/
- Click on
- For now, everything can default except the Origin. In this example, I’m using my sandbox S3 bucket
5. Scroll down and press the
Create Distribution button
The distribution will start deploying and it can take a while sometimes to propagate. Once it's done you’ll see something
Then you can pull assets from the bucket now using the Origin url https://d1zq4ei7l1j6ct.cloudfront.net. Accessing bucket objects for this will be going to the closes Edge Location for it rather than back to the origin.
Beyond the scope of this article but you could set up something like a bucket in one region e.g. London and then VPN to Sydney. Try curling the asset directly in the bucket and seeing what kind of download speed and latency you’re getting. Then do the same for the CloudFront one and see the difference.
This was just a lighter touch on Cloudfront, there are actually quite a few areas you can go into. I will decide tomorrow if I want to continue being exhaustive or to move around a bit. I’ve got a list right now of a few things I’d like to cover off:
- Load Balancers
- Auth (IAM’s)
- DNS (Route53)
- Databases (RDS, DynamoDB)
- SNS / SQS / API Gateways
- + more
I’d like to finish getting through this before 2021 ideally, so I can take the associate exam. That being said, I’ve also got some other things I’m learning in more depth alongside this with a little cross over (Serverless Architecture using AWS Lambdas and a React frontend). I might write some stories about that as I go as well.
What is Amazon CloudFront?
Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html…