Invalidations


Here is where things can get expensive. Say you upload a picture of a cat to S3, and that propagates out to the CloudFront CDN and all of its edge servers. Once CloudFront has the image cached, they don’t call back to S3 to reload that image until the TTL expires.

That means if you want to change the content of a file stored on CloudFront, you would have to invalidate the cached file. For example, if you did a production deployment and had a new CSS for a new feature. This can prove costly over time; therefore, I would not suggest doing frequent invalidations on CloudFront.

Instead, I would recommend changing the path at which the file is referenced. So, say you had a picture that changed every hour, for example, a thumbnail for an IoT camera. Instead of calling that ‘/camera.jpg,’ you would want something like ‘/2023-11-1_16-camera.jpg’ and code your application to reference the new image. This will spare you those costly invalidations.