Monday, June 30, 2025

CloudFront | Cache Invalidations.

 

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

 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 twtech Creates Invalidation

AWS Console

1.     Go to your 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

AWS CLI

#  bash 
aws cloudfront create-invalidation \
  --distribution-id YOUR_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 your 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

Kubernetes Clusters | Upstream Vs Downstream.

  The terms "upstream" and "downstream" in the context of Kubernetes clusters often refer to the direction of code fl...