Use PutBucketTagging with a CLI - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use PutBucketTagging with a CLI

The following code examples show how to use PutBucketTagging.

CLI
Amazon CLI

The following command applies a tagging configuration to a bucket named amzn-s3-demo-bucket:

aws s3api put-bucket-tagging --bucket amzn-s3-demo-bucket --tagging file://tagging.json

The file tagging.json is a JSON document in the current folder that specifies tags:

{ "TagSet": [ { "Key": "organization", "Value": "marketing" } ] }

Or apply a tagging configuration to amzn-s3-demo-bucket directly from the command line:

aws s3api put-bucket-tagging --bucket amzn-s3-demo-bucket --tagging 'TagSet=[{Key=organization,Value=marketing}]'
PowerShell
Tools for PowerShell V4

Example 1: This command applies two tags to a bucket named cloudtrail-test-2018: a tag with a key of Stage and a value of Test, and a tag with a key of Environment and a value of Alpha. To verify that the tags were added to the bucket, run Get-S3BucketTagging -BucketName bucket_name. The results should show the tags that you applied to the bucket in the first command. Note that Write-S3BucketTagging overwrites the entire existing tag set on a bucket. To add or delete individual tags, run the Resource Groups and Tagging API cmdlets, Add-RGTResourceTag and Remove-RGTResourceTag. Alternatively, use Tag Editor in the Amazon Management Console to manage S3 bucket tags.

Write-S3BucketTagging -BucketName amzn-s3-demo-bucket -TagSet @( @{ Key="Stage"; Value="Test" }, @{ Key="Environment"; Value="Alpha" } )

Example 2: This command pipes a bucket named cloudtrail-test-2018 into the Write-S3BucketTagging cmdlet. It applies tags Stage:Production and Department:Finance to the bucket. Note that Write-S3BucketTagging overwrites the entire existing tag set on a bucket.

Get-S3Bucket -BucketName amzn-s3-demo-bucket | Write-S3BucketTagging -TagSet @( @{ Key="Stage"; Value="Production" }, @{ Key="Department"; Value="Finance" } )
  • For API details, see PutBucketTagging in Amazon Tools for PowerShell Cmdlet Reference (V4).

Tools for PowerShell V5

Example 1: This command applies two tags to a bucket named cloudtrail-test-2018: a tag with a key of Stage and a value of Test, and a tag with a key of Environment and a value of Alpha. To verify that the tags were added to the bucket, run Get-S3BucketTagging -BucketName bucket_name. The results should show the tags that you applied to the bucket in the first command. Note that Write-S3BucketTagging overwrites the entire existing tag set on a bucket. To add or delete individual tags, run the Resource Groups and Tagging API cmdlets, Add-RGTResourceTag and Remove-RGTResourceTag. Alternatively, use Tag Editor in the Amazon Management Console to manage S3 bucket tags.

Write-S3BucketTagging -BucketName amzn-s3-demo-bucket -TagSet @( @{ Key="Stage"; Value="Test" }, @{ Key="Environment"; Value="Alpha" } )

Example 2: This command pipes a bucket named cloudtrail-test-2018 into the Write-S3BucketTagging cmdlet. It applies tags Stage:Production and Department:Finance to the bucket. Note that Write-S3BucketTagging overwrites the entire existing tag set on a bucket.

Get-S3Bucket -BucketName amzn-s3-demo-bucket | Write-S3BucketTagging -TagSet @( @{ Key="Stage"; Value="Production" }, @{ Key="Department"; Value="Finance" } )
  • For API details, see PutBucketTagging in Amazon Tools for PowerShell Cmdlet Reference (V5).

For a complete list of Amazon SDK developer guides and code examples, see Developing with Amazon S3 using the Amazon SDKs. This topic also includes information about getting started and details about previous SDK versions.