Amazon S3 Command Line Copy all objects to themselves setting Cache control


I have an Amazon S3 bucket with about 300K objects in it and need to set the Cache-control header on all of them. Unfortunately it seems like the only way to do this, besides one at a time, is by copying the objects to themselves and setting the cache control header that way:

Is the documentation for the Amazon S3 CLI copy command but I have been unsuccessful setting the cache control header using it. Does anyone have an example command that would work for this. I am trying to set cache-control to max-age=1814400

Some background material:


By default, aws-cli only copies a file’s current metadata, EVEN IF YOU SPECIFY NEW METADATA.

To use the metadata that is specified on the command line, you need to add the ‘–metadata-directive REPLACE’ flag. Here are some examples.

For a single file

For an entire bucket:

A little gotcha I found, if you only want to apply it to a specific file type, you need to exclude all the files, then include the ones you want.

Only jpgs and pngs

Here are some links to the manual if you need more info:

Leave a Reply