You are on page 1of 5

Amazon CloudFront (AWS's CDN)

 What is Amazon CloudFront?


 How does Amazon CloudFront work?
 Why is CloudFront an essential part of the Serverless architecture?
 How does CloudFront integrate with other AWS services?
 How does CloudFront work with the Serverless Framework?
 Benefits of using CloudFront
 Disadvantages
 Locations
 Pricing
 Alternatives
 CloudFront v/s S3
 FAQ
 Resources & Getting Started
What is Amazon CloudFront?
Amazon CloudFront is a content delivery network (CDN) provided by Amazon Web
Services. By using a CDN, companies can accelerate delivery of files to users over
the Internet while also reducing the load on their own infrastructure. CloudFront is
AWS’s own CDN solution that integrates with other AWS products, so it’s convenient
for companies already running on AWS.

How does CloudFront work?


CloudFront acts as a distributed cache for your files, with cache locations around the
world. It fetches your files from their source location (“origin” in CloudFront terms)
and places the copies of the files in different edge locations across the Americas,
Europe, Asia, Africa, and Oceania. In so doing, CloudFront speeds up access to
your files for your end users.

Why is this worth doing? Imagine, for example, that your data origin is located in
Brazil and one of your customers in Japan would like to access this data. Without
CloudFront (or a similar solution) this customer would need to send a request to the
other side of the world, transferring the files from a very distant location. This would
result in a request that’s slow to arrive to the destination as well as a slow file
download. Having your customers wait longer to get data often makes for a poor
customer experience.

With CloudFront, however, the files are periodically fetched by CloudFront system
from the location in Brazil and placed onto a set of servers around the world,
including one in Japan. When a user in Japan goes to download the files, the
request will now be served by a nearby server

Why is CloudFront an essential part of the Serverless


ecosystem?
CloudFront allows Serverless applications to provide a fast and low-latency experience to
end users by making sure that the static parts of their application load fast, irrespective of
where its users are. CloudFront achieves this while also allowing developers to pay only for
what they use and to scale their systems on demand. That’s what makes CloudFront an
essential part of the Serverless ecosystem.

How does CloudFront integrate with other AWS services?


To speak of CloudFront being integrated with another AWS service chiefly refers to
CloudFront’s ability to use that service as a data source for distribution. These
integrations include:
Amazon S3. It’s possible (and in fact very common) to use an Amazon S3 bucket as
a source from which CloudFront will request files before placing them in its edge
locations. This works both with standard S3 buckets and with buckets configured
as website endpoints. When CloudFront is configured, the S3 bucket can continue to
be used with no changes.

Amazon EC2. CloudFront supports using an Amazon EC2 server or an Elastic Load
Balancing endpoint as an origin for files in a CloudFront distribution. CloudFront’s
support for custom HTTP/HTTPS origins is what enables this integration, meaning
that it’s also possible to use a non-EC2 server as a file origin.

Amazon CloudWatch. Every CloudFront distribution emits Amazon CloudFront metrics


for metrics such as total number of requests, error rates, and Lambda@Edge
throttles and execution errors. These metrics are available with no additional
configuration and don’t count against CloudWatch limits, making it a good starting
point for monitoring your CloudFront usage.

Benefits of using CloudFront


Using CloudFront provides Serverless developers with a number of benefits,
discussed below.

Scalability CloudFront distributions scale automatically with the number of requests


your files are getting and require no configuration changes to respond to increased
load, making CloudFront a great choice for serving the static content of a website or
a fast-growing application.

Ease of setup Setting up a CloudFront distribution is quite easy when using S3 or


even a custom HTTP/HTTPS endpoint as a file origin. Once set up, CloudFront
requires no maintenance to continue working. Low maintenance means extra time
for more productive tasks like building out the business logic of your application.

Flexible configuration You can customize your CloudFront distributions to have


different caching policies based on the kinds of files you’re serving. So, for example,
if you have different kinds of content being served from the same domain and you
want to apply different file expiration rules in the CloudFront cache to different
sections of your website or application, you can do so on a very granular level.

Disadvantages of using CloudFront


Using CloudFront also comes with a few drawbacks that you need to be aware of
before you decide to use it in production.

High cost at scale CloudFront pricing is pay-per-use. This means you pay very little
if the traffic to your Serverless site or application is low. However, as the traffic
grows, the cost of using CloudFront can increase very rapidly.
You can avoid surprises with CloudFront bills by establishing a process to regularly
review your CloudFront usage and give your accounting teams a heads up if any
significant increases in CloudFront traffic (and thus cost) are expected as you
develop your application.

We also recommend only using CloudFront for files where delivery time and speed is
truly important, for example, the assets for your main website’s marketing pages. It’s
likely that most of the files you distribute to your users can be shared directly from S3
or another file storage solution without much impact to the customer experience.
Customer invoices, user-generated video content, and short-lived assets probably
don’t need to be part of your CloudFront distributions.

Lack of visibility into the underlying CloudFront structure When using a


managed service, ease of use and configuration frequently trades off for the control
you would normally have over the underlying infrastructure. CloudFront is a
proprietary solution, and while Amazon provides a guide on optimizing CloudFront
caching performance, you don’t get a lot of visibility into how exactly caching is
performing in every region and for every request type. This can sometimes result in
slower performance compared to a similar self-hosted solution that you can tweak for
your exact use case.

CloudFront Locations
CloudFront currently offers around 200 edge locations—which consist of content
caches and supporting infrastructure—on five continents. You’ll find the highest
density of edge locations in the United States, Western Europe, and East Asia.

In addition, CloudFront offers 11 regional edge caches in AWS regions around the
world, which act as caches for the caches; instead of having all 200 edge locations
get the original files from your servers, the regional edge caches retain the most
frequently accessed files and serve them to the edge location when it requests the
updated version of a file.

A full list of CloudFront locations, including edge locations and edge caches, is
available on the CloudFront website’s features page.

Amazon CloudFront Pricing


With the AWS free tier, during the 12 months after your account was created, AWS
provides 50GB of free outbound data transfer and 2 million free HTTP/HTTPS
requests to your CloudFront distributions per month. The free tier also includes 1,000
free invalidation requests per month. This is generally enough to experiment with
using CloudFront but insufficient for production use.

Amazon CloudFront Alternatives


CloudFront is the only CDN service offered by AWS, but there are other services
from Amazon and from other providers that you could use to achieve the same
goal—giving your users fast access to your static files at scale.
Amazon S3 Amazon S3 is a cloud file-storage solution from Amazon, and while it’s
not a CDN like CloudFront, it can work well for the purpose of distributing files to
your end users. With both CloudFront and S3 alike, the core of the cost is the data
transfer from file storage to your end users. S3 can be cheaper, since you’ll only pay
for data transfer from your region of origin, while with CloudFront you’ll be paying for
data transfer in all regions where your users access the files. This can of course
include regions where data transfer is very expensive, for example, South America
or Australia.

But using S3 will also likely be slower for your end users, unless they all happen to
be located near the region where your S3 bucket is hosted.

In short, using S3 directly (without CloudFront) can be a good option for cases where
a small amount of extra latency is acceptable for your users.

Google Cloud CDN Google Cloud CDN offers very similar functionality to that of
CloudFront. The key difference is the pricing structure: Google Cloud CDN exposes
more detail about the cache structure and charges for cache lookups, cache fill data
transfer, and cache egress data transfer. The total cost of using Google Cloud CDN
should be in the same range as CloudFront, as most of the cost still lies in the data
transfer charges, and data transfer is priced similarly for both services. The extra
visibility you get into the details of how Google Cloud CDN works through their
pricing model can allow you to reduce the CDN’s cost and optimize its performance.

CloudFlare CDN CloudFlare is a company that provides CDN and related solutions.
The technical implementation of their CDN solution is different from that of
CloudFront and Google Cloud CDN: CloudFlare is built as a reverse proxy.
CloudFlare’s customers point the name servers for their domain(s) to CloudFlare,
whose CDN service then becomes the primary endpoint for all HTTP or HTTPS
requests each domain receives. CloudFlare retrieves any files it’s missing from the
customer’s backend server.

When should I use Amazon CloudFront vs S3?


We generally recommend using CloudFront only in cases where faster download
speeds and lower latency for your files will result in a significant improvement in
customer experience. This includes cases like hosting the homepage of your
marketing website on CloudFront instead of S3.

For all cases where latency and download speed are less crucial, we recommend
using S3 directly to reduce the total operating cost of your system.

You might also like