Can you tag individual S3 objects in AWS?
Asked Answered
L

7

14

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?

Lida answered 4/10, 2012 at 16:32 Comment(1)
Are you talking about cost allocation tagging?Rumanian
C
16

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.

Centurion answered 1/12, 2016 at 5:24 Comment(3)
Perhaps the API documentation hasn't been updated yet, because the new Object Tagging section in the S3 Developer Guide does say: "With tagging, you now have another dimension. [...] You can also list objects in your bucket by specifying tag filter."Monumental
You can search now using aws athena.Junna
can we send x-amz-tagging of an object as header through postman ?Poteen
C
5

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.

http://docs.amazonwebservices.com/AmazonS3/latest/dev/UsingMetadata.html

Coates answered 5/10, 2012 at 5:23 Comment(0)
T
4

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:
    s3.put_object_tagging(
        Bucket = bucketName,
        Key = obj.key,
        Tagging = tagging
        )
Theurgy answered 5/5, 2018 at 12:40 Comment(2)
A word of caution: Adding Tags requires additional permissions. Ordinary read/write/list/delete on a S3 bucket will not be enough. If you don't have permission, it won't even record the error in CloudTrail. You will only get a 403 error with "access denied".Lenee
Does this work with cost allocation too? can you see per-object cost if you tag each object with a different tag value?Resemble
M
3

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.

Menfolk answered 4/10, 2012 at 20:45 Comment(1)
Mutable object level tags are now available as of reInvent:2016. See Kobi's answer below.Perforce
S
3

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

Summers answered 26/12, 2016 at 11:7 Comment(0)
N
0

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!

Nicolettenicoli answered 11/9, 2015 at 9:54 Comment(0)
J
0

Yes, you can tag objects...but not for cost allocation:

Perhaps it is important to draw a distinction between cost allocation tags, and labelling objects with tags. To quote the Amazon documentation: "Cost allocation tags can only be used to label buckets. For information about tags used for labeling objects, see Object Tagging"

Labels: Tagging an object in a bucket:

These are much like meta-data key value pairs defined by users themselves:

Tagging in an object

Johns answered 20/3, 2020 at 4:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.