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.

Need Your Help

error messge output not displaying correctly

laravel laravel-5 laravel-5.2 laravel-validation

could someone show me how to get the :other or :after_field to display in the error message.

ADO.NET and ExecuteNonQuery: how to use DDL

sql-server ddl executenonquery

I execute SQL scripts to change the database schema. It looks something like this: