+7 votes
in Amazon Web Service by

It appears as though I can only use tags at the bucket level in S3. That seems to make sense in a way, because you would likely only do billing at that kind of macro level. However, I can see a few use cases for tagging so that different folks get billed for different objects in the same bucket.

Can you tag individual S3 objects?

6 Answers

+8 votes

Object tagging is a new feature, announced at December, 2016. From the announcement:

With S3 Object Tagging you can manage and control access for Amazon S3 objects. S3 Object Tags are key-value pairs applied to S3 objects which can be created, updated or deleted at any time during the lifetime of the object. With these, you’ll have the ability to create Identity and Access Management (IAM) policies, setup S3 Lifecycle policies, and customize storage metrics. These object-level tags can then manage transitions between storage classes and expire objects in the background.

See also: S3 » Objects » Object Tagging

At the moment, it doesn't look like you can search by tags, or that object tagging affects billing.

+2 votes

It's not "tagging" for the purpose of AWS-side billing, but you can use object metadata to store whatever data you'd like for an object.


+2 votes

According to documentation you can only tag buckets:

Cost allocation tagging allows you to label S3 buckets so you can more easily track their cost against projects or other criteria..

It is consistent with what you can see in both management console and SDK documentation.

Of course you could use folder/object metadata to do a finer "tagging" on your own, but I think you will find a better solution.

+2 votes

S3 tags are new feature released on 29 Nov, 2016. Tags can be added on bucket and on individual objects. S3 tags are exciting feature as you can keep business taxonomy data, even control access.release of s3 tag feature s3 tags can be added using new s3 console from browser. To add tag from browser, assuming you are on new s3 console. Select the item --> More --> Add tag.

add tag using new console.

To view tag, click on object using new console and view properties. view tag using new console.

Aws S3 cli currently not supporting tag feature. Aws s3 api are providing way to add and read tag on object. add tag using s3 api,get tag using s3 api

+1 vote

Now, we can add tags to each object. Using AWS S3API,

aws s3api put-object-tagging --bucket bucket_name --key key_name --tagging 'TagSet=[{Key=type,Value=text1}]'

We can also add tags to objects using python API. Following code snippet add tags to all objects in bucket. You can pass object name if you want to add tag to just one object.

session = aws_session.set_aws_session()

s3 = boto3.Session(aws_access_key_id, aws_secret_access_key)

bucketName = 'bucketName'
bucket = s3.Bucket(bucketName)

object_list = bucket.objects.all()

s3 = session.client('s3')

tagging = {'TagSet' : [{'Key': 'CONF', 'Value':'No'}]}

for obj in object_list:
        Bucket = bucketName,
        Key = obj.key,
        Tagging = tagging
0 votes

I don't think you can tag individual items in S3 the same way you can generally tag resources.

However you can add metadata to items in S3 to identify them. You could then report on items with different types by either: - Paging through items in the bucket (obviously rather slow) and collating any information you want about them - Having an external metadata store in a database of your choice, which you could then use to run reports. For example how many items of different types, total size, etc. Of course anything you would want to report on would have to be added to the database first

I would definitely be interested in any better solutions though!

Welcome to Kloudwise, where you can ask any AWS, Azure, GCP and other cloud service questions and receive answers from other members of the community.