AWS website served via S3: configure cache

Elvis Ciotti
Aug 18, 2024

--

Add the “cache-control” to the “aws s3 cp” command

aws s3 cp static/ s3://YOUR_BUCKET/ 
--recursive --cache-control max-age=31536000

And test from the S3 console with any file, from S3 object actions panel

Wipe the cloudfront cache

aws cloudfront create-invalidation --distribution-id <YOUR_DIST> --paths "/*"

Then you can test via curl

/ $ curl -I https://YOUR_BUCKET_URL/file.css | grep cache
cache-control: max-age=31536000
x-cache: Hit from cloudfront

--

--

Elvis Ciotti
Elvis Ciotti

Written by Elvis Ciotti

Software Contractor — Java, Spring, k8s, AWS, Javascript @ London - hire me at https://elvisciotti.github.io/

No responses yet