Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting HTTP headers for all files in AWS S3 bucket

Ive have been able to figure out how to set the http header, cache-control: max_age on a single file using the AWS console. However, I would like to do it for all files in a S3 bucket.

How do I go about doing that for say 500 files in one bucket? I can't do it for each individual file using the AWS console.

If you can't do it through AWS. can you recommend a third party app?

Thanks, Jeff

like image 427
jeff_horsch Avatar asked Jan 11 '23 10:01

jeff_horsch


2 Answers

This has since been improved, you can edit folder metadata in the console, just select the folder(s) or file(s), press Actions, choose Change Metadata and you'll be presented with a panel like this:

enter image description here

in https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html

like image 101
jmng Avatar answered Jan 17 '23 22:01

jmng


The only way to modify object metadata is to make copy of the object and set the metadata. In the copy operation you set the same object as the source and target.

— http://docs.aws.amazon.com/AmazonS3/latest/dev/CopyingObjectsExamples.html

This is the operation that the console is doing for you, behind the scenes. There is no batch operation provided.

You'll need to write some code to iterate through the objects in the bucket and call the api for each object you want to modify.

Or, find a tool or library that can do that for you. Which tool and where to find it are questions outside the scope of Stack Overflow.

like image 30
Michael - sqlbot Avatar answered Jan 17 '23 23:01

Michael - sqlbot