Borislav Hadzhiev
Thu Sep 16 2021·2 min read
Photo by Rashel Ochoa
To tag an S3 object with the AWS CLI, use the put-object-tagging
command.
aws s3api put-object-tagging --bucket your_bucket --key dog.png --tagging "{\"TagSet\": [{\"Key\": \"department\", \"Value\": \"accounting\"}]}"
The command creates a tag with a key of department
and a value of
accounting
.
If the S3 object is nested in a "directory", pass the --key
parameter as the
whole path that leads to the object, i.e. /static/images/dog.png
.
put-object-tagging
command deletes any tags the S3 object previously had, before creating the new tags.To verify the S3 object got tagged successfully, run the get-object-tagging
command:
aws s3api get-object-tagging --bucket your_bucket --key dog.png
To create multiple tags on an S3 object with the AWS CLI, pass multiple
key:value
pair objects in the --tagging
parameter:
aws s3api put-object-tagging --bucket your_bucket --key dog.png --tagging "{\"TagSet\": [{\"Key\": \"department\", \"Value\": \"accounting\"}, {\"Key\": \"color\", \"Value\": \"green\"}]}"
To verify that both of the tags were created on the S3 object, run the
get-object-tagging
command:
aws s3api get-object-tagging --bucket your_bucket --key dog.png