Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 932
Abhishek Jain Avatar asked Feb 06 '14 14:02

Abhishek Jain


People also ask

What happens when an S3 object expires?

During this time, based on their expiration dates, any object found to be expired will be queued for removal. You will not be billed for any associated storage for those objects on or after their expiration date. If server access logging has been enabled for that S3 bucket, an S3. EXPIRE.

Does S3 Putobject overwrite?

If an object already exists in a bucket, the new object will overwrite it because Amazon S3 stores the last write request.


1 Answers

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.

like image 195
Mauvis Ledford Avatar answered Sep 20 '22 18:09

Mauvis Ledford