You are viewing the preview version of this book
Click here for the full version.

Integrating with CloudFront

Why use CloudFront

CloudFront is the CDN solution offered by AWS which means it has edge locations all around the globe to provide servers geographically closer to the users. This is especially beneficial for static public files as those can be cached in the distributed network greatly shortening the distance the packets need to travel.

But signed URLs are not like this, yet they can still benefit from utilizing this CDN. First, edge locations do shorten response times even if the data is in a central location. This is possible due to reusing the origin connection across different users. But this is not a significant boost.

More importantly, CloudFront supports HTTP/2 and above allowing connection multiplexing. If the browser uses HTTP/1.1 then it uses a limited number of threads, usually around 5, to download each file. This wastes a lot of time just sending the next request after one is finished, which becomes really pronounced when you download a lot of small files. In contrast, with HTTP/2 all the files are downloaded in parallel. See this page for a demonstration on this difference.

Another speed-related benefit is the ability to take advantage of caching on the edge locations. As signed URLs are generally non-cacheable, this is a more involved topic, which we'll cover in the Proxy caching section.

Besides just putting CloudFront in front of an S3 bucket, you can also configure it to serve your frontend and backend too. In this case, signed URLs are served from the same domain, which not only eliminates all problems with CORS, but also simplifies the frontend code and the Content-Security Policy, as well as further speeding up downloads by saving a TLS handshake.

CloudFront benefits
  • Speeds up small files with HTTP/2
  • Simplifies domain configuration
  • Allows proxy caching

How to setup CloudFront

There is more, but you've reached the end of this preview
Read this and all other chapters in full and get lifetime access to:
  • all future updates
  • full web-based access
  • PDF and Epub versions