0
votes

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?

1
If you are using cloudfront, then what do you mean by "serving static files from flask"? Don't you want all static files served by the cdn?dkarchmer
When I deploy my Elastic Beanstalk application, it uploads a zipped file of the application to S3. I'm using this as one of the origins to my CDN (another other origin is a being a bucket for images for the application). I assumed that the static files in the static folder were going through the CDN but on second thoughts, it's not. Is there a way to upload static files to the S3 on eb deploy or do I need to write a script to do that?user5211736

1 Answers

0
votes

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.