AWS Elastic Beanstalk / S3 / CloudFront Cache-Control Header
I have a Flask application deployed using AWS Elastic Beanstalk. I am using S3 for storage and CloudFront as a cdn. How can I add the Cache-Control header to the static files served by Elastic Beanstalk application?
Elastic Beanstack assumes a very simplistic setup when it comes to static files. Basically assumes that you will serve them from the server itself.
Most people, like you, use S3 and CloudFront instead, but unfortunately, this requires you to deploy these static files manually (i.e. without eb).
If your static files don't change much, you could just upload them manually to your s3 origin. But may be better to script this.
I personally use Gulp to manage all my static files. Gulp has two handy packages to deploy to S3, and setup the Cache controls:
It's not hard to do the same with Boto, but Gulp also processes my CSS/JS files, including creating a cache friendly deployment name (e.g. app-1234.css). My deployment to Elastic Beanstalk is then:
gulp deploy # Where Gulp processes CSS/JS/Images and uploads to S3/CF eb deploy # To deploy my python code
Hope this helps.