12 - CloudFront & AWS Global Accelerator

CloudFront - Cache Invalidation

awscloudfrontcache-invalidationttlsaa-c03

Overview

If you update the backend origin, CloudFront edge locations do not know about it. They only fetch the refreshed content once the TTL of the cache expires. If you want the new content served sooner, you can force a full or partial cache refresh, bypassing the TTL. This is a CloudFront invalidation.

You pass in file paths to invalidate:

Pattern Effect
* Invalidate all files
/index.html Invalidate a specific file
/images/* Invalidate a path (all images)

Example Flow

  1. A distribution has two edge locations. Each has its own cache with index.html and images from the S3 origin, with a TTL of one day.
  2. An admin updates the S3 bucket: adds or changes images and changes index.html.
  3. The admin invalidates /index.html and /images/*.
  4. CloudFront tells the edge locations to remove those files from their cache.
  5. On the next user request, the edge location finds the file is not in its cache, requests it from the origin, and gets the updated index.html.
Exam Tip

Origin content changed but users still see old content at the edge -> create a CloudFront invalidation instead of waiting for the TTL.


Cache invalidation flow

Adminupdates S3 origin S3 originnew index.html 1. change files Invalidation/index.html, /images/* 2. tell edges Edge location 1file removed Edge location 2file removed 3. next request fetches updated file Without invalidation, edges serve old content until the TTL expires.
The invalidation removes files from edge caches so the next request refetches from the origin.

Questions & Answers

Q1: How do you make CloudFront serve updated origin content immediately?

Answer:

Run a cache invalidation for specific paths (e.g. /index.html, /images/*) or everything (*).

Q2: Without invalidation, when do edge locations get new content?

Answer:

Only after the TTL of the cached object expires.

Check yourself

Quiz

Flashcards

Click the card (or focus it), then use ← → to move and Space to flip.