There are more AWS SDK examples available in the AWS Doc SDK Examples
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
tagexample attaches the specified tag key and value pairs to the specified resource group (the group itself, not its members).aws resource-groups tag \ --tagsQueryType=tags,QueryResources=ec2-instances\ --arnarn:aws:resource-groups:us-west-2:128716708097:group/tbq-WebServerOutput:
{ "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 V4
-
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/workboxesOutput:
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 (V4).
-
- Tools for PowerShell V5
-
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/workboxesOutput:
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 (V5).
-