AWS Mobile Blog

AWS Amplify Console supports instant cache invalidation and delta deployments on every code commit

*This article was written by Nikhil Swaminathan & Dan Green from the AWS Amplify Console team.

The Amplify Console now supports instant cache invalidation, which enables you to deploy updates to your single page or static app instantly—without giving up the performance benefits of content delivery network (CDN) caching. This means that you no longer have to worry about setting time-to-live (TTL) values or waiting on cache invalidation requests to propagate your changes. You can ‘git push’ your code and see your changes instantly after the build succeeds. With delta deployments, only modified files are redeployed, which improves deployment times for very large websites.

If you missed our re:Invent launch, the AWS Amplify Console provides a complete workflow for developing, deploying, and hosting single-page web apps or static sites with serverless backends. To get started, connect your repo to the AWS Amplify Console.

Hosting on CDNs

The Amplify Console provides hosting for modern web apps (single-page apps or static site generators) through the CloudFront CDN. A CDN is a network of distributed servers that cache files at edge locations across the world. CDNs enable high-performance web hosting by caching static assets (HTML, CSS, JavaScript, and images) at all the edge locations—so that a user visiting from Japan is served content from Tokyo, while a user visiting from Brazil is served the same content from São Paulo. CDNs use a configuration called TTL to determine how long content stays cached at the edge locations. To update content in the CDN, developers are required to invalidate (or bust) the cache.

Challenges with cache invalidations on CDNs

Updating content requires you to invalidate the CDN cache. Invalidating the cache forces edge locations to fetch new content from the origin, which updates the content. To enable frequent updates, you have a few options:

  • Set a low TTL (0–5 seconds) for the cache – This enables almost-instant updates, but adversely impacts performance because the CDN cache is busted every 5 seconds to fetch new content from the origin. A longer TTL improves web performance, but makes deploying updates problematic.
  • Manually invalidate the cache on every update – This works for web apps that are updated once or twice a year. However, in an era of rapid prototyping and minimum viable products, developers want the ability to make frequent updates without having to wait 15–20 minutes for content to propagate.
  • Hash file names at build time – This provides a solution to update files, but requires manual implementation for developers to add this to their build phase.

Instant cache invalidation with the Amplify Console

With instant cache invalidation, Amplify Console users no longer have to make a trade-off between faster deployment and faster performance. The Amplify Console offers instant cache invalidation by:

  • Creating unique references to all the build artifacts (for example, HTML, JavaScript, and media files).
  • Requiring browsers to check for updates from the CDN on every request.

The first time you deploy your site, the Amplify Console versions all assets to create unique references for each file. These references are deployed to our origin and are made available to our CDN cache, which has a very high TTL. We set cache-control headers on all static asset metadata to force the browser to check for asset updates on every request.

If the files match what’s on the CDN, the browser serves assets from its own cache. Otherwise, it fetches the new content from the origin. When you deploy an update, the modified files are uniquely identified, pushed to the origin, and are then ready to be fetched by the next request.

Web apps hosted on the Amplify Console perform at a comparable level to ones hosted on Amazon CloudFront with Amazon S3 — plus Amplify gives you additional benefits out-of-the-box, such as instant cache invalidation, feature branch deployments, redirects, and password protection.

Delta deployments

Additionally, Amplify Console now supports delta deployments. This feature significantly speeds up deployment times for users with very large sites. It ensures that only assets that are modified during each build are deployed. The following image shows a number of files that skip deployment during a build.

Get started

If you’re an existing Amplify Console customer, you need to redeploy your site once to activate the instant cache invalidation feature. If you’re a new user, you can simply connect your repo to the AWS Amplify Console.