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.

Buy me a coffee if you found this helpful.

© Copright 2024 Schematical
17 S. Fairchild St. FL 7, Madison, WI 53703
DISCLAIMER: The information provided is for general informational purposes only. Posts and other information may not be updated to account for changes in the law and should not be considered advice. None of the articles or posts on this website are intended to create an attorney-client relationship. You should consult with legal and/or financial advisors for legal and tax advice tailored to your specific circumstances.