There are more AWS SDK examples available in the AWS Doc SDK Examples
Use GetObjectTagging
with an AWS SDK or CLI
The following code examples show how to use GetObjectTagging
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- CLI
-
- AWS CLI
-
To retrieve the tags attached to an object
The following
get-object-tagging
example retrieves the values for the specified key from the specified object.<userinput>aws s3api get-object-tagging \ --bucket <replaceable>my-bucket</replaceable> \ --key <replaceable>doc1.rtf</replaceable></userinput>
Output:
{ "TagSet": [ { "Value": "confidential", "Key": "designation" } ] }
The following
get-object-tagging
example tries to retrieve the tag sets of the objectdoc2.rtf
, which has no tags.<userinput>aws s3api get-object-tagging \ --bucket <replaceable>my-bucket</replaceable> \ --key <replaceable>doc2.rtf</replaceable></userinput>
Output:
{ "TagSet": [] }
The following
get-object-tagging
example retrieves the tag sets of the objectdoc3.rtf
, which has multiple tags.<userinput>aws s3api get-object-tagging \ --bucket <replaceable>my-bucket</replaceable> \ --key <replaceable>doc3.rtf</replaceable></userinput>
Output:
{ "TagSet": [ { "Value": "confidential", "Key": "designation" }, { "Value": "finance", "Key": "department" }, { "Value": "payroll", "Key": "team" } ] }
-
For API details, see GetObjectTagging
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: The sample returns the tags associated with the object present on the given S3 bucket.
Get-S3ObjectTagSet -Key 'testfile.txt' -BucketName 'testbucket123'
Output:
Key Value --- ----- test value
-
For API details, see GetObjectTagging in AWS Tools for PowerShell Cmdlet Reference.
-