Use Tag with a CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use Tag with a CLI

The following code examples show how to use Tag.

CLI
AWS CLI

To attach a tag to a resource group

The following tag example attaches the specified tag key and value pairs to the specified resource group (the group itself, not its members).

aws resource-groups tag \ --tags QueryType=tags,QueryResources=ec2-instances \ --arn arn:aws:resource-groups:us-west-2:128716708097:group/tbq-WebServer

Output:

{ "Arn": "arn:aws:resource-groups:us-west-2:128716708097:group/tbq-WebServer", "Tags": { "QueryType": "tags", "QueryResources": "ec2-instances" } }

For more information, see Manage tags in the AWS Resource Groups User Guide.

  • For API details, see Tag in AWS CLI Command Reference.

PowerShell
Tools for PowerShell

Example 1: This example adds tag key 'Instances' with value 'workboxes' to the given resource group arn

Add-RGResourceTag -Tag @{Instances="workboxes"} -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes

Output:

Arn Tags --- ---- arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {[Instances, workboxes]}
  • For API details, see Tag in AWS Tools for PowerShell Cmdlet Reference.