Reputation:
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?
Upvotes: 14
Views: 30367
Reputation: 35595
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"
These are much like meta-data key value pairs defined by users themselves:
Upvotes: 0
Reputation: 658
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
)
Upvotes: 4
Reputation: 2135
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.
To view tag, click on object using new console and view properties.
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
Upvotes: 3
Reputation: 138027
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.
Upvotes: 17
Reputation: 457
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!
Upvotes: 0
Reputation: 6945
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
Upvotes: 5
Reputation: 14521
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.
Upvotes: 3