AWS S3 cli – tag all objects within a directory

Question:

Is there a way to apply a tag (or set of tags) to all objects in an S3 directory using one single put-object-tagging cli command?

I.e if I have two files (test0.txt, test.txt) I can do the run the following two commands:

When trying to pass the folder itself as the –key option I get the following error (as it must reference a single object):

Is there a workaround for this?

Answer:

There is no concept of a directory in S3. Here is a crude way of achieving what you want. Other posters may have a better solution. The following solution first gets all the objects in the folder and then calls put-object-tagging for each one of them. Note: I didn’t test this solution.

Leave a Reply