How to set expires headers to all images in a bucket in Amazon S3

Abhishek Jain picture Abhishek Jain · Feb 6, 2014 · Viewed 22.2k times · Source

We have around 10,000+ images in a bucket in Amazon S3, how can I set the expires header on all of the images in one go?

Answer

Mauvis Ledford picture Mauvis Ledford · May 13, 2015

Just a heads up that I found a great solution using the AWS CLI:

aws s3 cp s3://bucketname/optional_path s3://bucketname/optional_path --recursive  --acl public-read  --metadata-directive REPLACE --cache-control max-age=2592000

This will set the Cache-Control for 30 days. Note that you have the option to copy or replace the previous header data. Since AWS will automatically include the right meta content-type data for each media type and I had some bad headers I just chose to overwrite everything.