Monday, June 30, 2025

CloudFront Cache Invalidations | Overview.

CloudFront Cache Invalidations - Overview. 

Scope:

  • Intro,
  • Architecture,
  • Benefits of Cache Invalidation,
  • Common Use Cases,
  • How CloudFront Cache Invalidations Works,
  • How to Create Invalidation via AWS Console
  • How to Creates Invalidation via AWS CLI,
  • Cost of Invalidation,

Intro:

  • CloudFront Cache Invalidation allows twtech to remove cached content from edge locations before it naturally expires (based on TTLs), 
  • CloudFront Cache Invalidation ensurs that users receive updated or corrected versions of twteh content immediately.

Architecture

 Benefits of Cache Invalidation:

CloudFront caches content at edge locations for performance and cost savings. But when the origin content changes, that cached version can become stale unless:

  •         twtech versions its files (recommended), or
  •         twtech explicitly invalidate the old content

 Common Use Cases

  •         After deploying new versions of assets (JS, CSS, images)
  •         Removing incorrect or sensitive content quickly
  •         Updating frequently changing static files

 How CloudFront Cache Invalidations Works

Invalidation removes specific files from the cache. The next time someone requests those files, CloudFront fetches the latest version from the origin.

  •         twtech  needs to specify the paths (wildcards supported)
  •         CloudFront returns HTTP 200 OK after successful invalidation

 How to Create Invalidation via AWS Console

1.     Go to CloudFront Distribution

2.     Choose the Invalidations tab

3.     Click Create Invalidation

4.     Enter file paths (e.g.):

# bash 
/index.html
/images/logo.png
/assets/*

5.     Submit

How to Creates Invalidation via AWS CLI

#  bash 
aws cloudfront create-invalidation \
  --distribution-id twtech_DISTRIBUTION_ID \
  --paths "/index.html" "/assets/*"

 Syntax Tips

Path

Description

/index.html

Only invalidates /index.html

/assets/*

Invalidates everything under /assets/

/*

Invalidates entire distribution (expensive)

 Cost of Invalidation

  •         First 1,000 paths/month: Free
  •         Additional paths: $0.005 per path (as of June 2024)
  •         One /* wildcard counts as one path

 What Invalidation Doesn’t Do

  •         Doesn’t delete content from twtech origin
  •         Doesn’t purge CloudFront logs or configurations
  •         Doesn’t remove objects from S3

twtech Best Practices

  •         Prefer versioning twtech files (e.g. main.v2.js) to avoid invalidations
  •         Use invalidations for critical fixes or edge cases
  •         Group invalidations together (use wildcards when practical)
  •         Monitor costs if twtech invalidates frequently.



No comments:

Post a Comment

Amazon EventBridge | Overview.

Amazon EventBridge - Overview. Scope: Intro, Core Concepts, Key Benefits, Link to official documentation, Insights. Intro: Amazon EventBridg...