Use DescribeTags with a CLI
The following code examples show how to use DescribeTags.
- CLI
-
- Amazon CLI
-
To describe all tags
This example describes all your tags.
aws autoscaling describe-tagsOutput:
{ "Tags": [ { "ResourceType": "auto-scaling-group", "ResourceId": "my-asg", "PropagateAtLaunch": true, "Value": "Research", "Key": "Dept" }, { "ResourceType": "auto-scaling-group", "ResourceId": "my-asg", "PropagateAtLaunch": true, "Value": "WebServer", "Key": "Role" } ] }For more information, see Tagging Auto Scaling groups and instances
in the Amazon EC2 Auto Scaling User Guide. Example 2: To describe tags for a specified group
To describe tags for a specific Auto Scaling group, use the
--filtersoption.aws autoscaling describe-tags --filtersName=auto-scaling-group,Values=my-asgFor more information, see Tagging Auto Scaling groups and instances
in the Amazon EC2 Auto Scaling User Guide. Example 3: To describe the specified number of tags
To return a specific number of tags, use the
--max-itemsoption.aws autoscaling describe-tags \ --max-items1If the output includes a
NextTokenfield, there are more tags. To get the additional tags, use the value of this field with the--starting-tokenoption in a subsequent call as follows.aws autoscaling describe-tags \ --filtersName=auto-scaling-group,Values=my-asg\ --starting-tokenZ3M3LMPEXAMPLEFor more information, see Tagging Auto Scaling groups and instances
in the Amazon EC2 Auto Scaling User Guide. -
For API details, see DescribeTags
in Amazon CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example describes the tags with a key value of either 'myTag' or 'myTag2'. The possible values for the filter name are 'auto-scaling-group', 'key', 'value', and 'propagate-at-launch'. The syntax used by this example requires PowerShell version 3 or later.
Get-ASTag -Filter @( @{ Name="key"; Values=@("myTag", "myTag2") } )Output:
Key : myTag2 PropagateAtLaunch : True ResourceId : my-asg ResourceType : auto-scaling-group Value : myTagValue2 Key : myTag PropagateAtLaunch : True ResourceId : my-asg ResourceType : auto-scaling-group Value : myTagValueExample 2: With PowerShell version 2, you must use New-Object to create the filter for the Filter parameter.
$keys = New-Object string[] 2 $keys[0] = "myTag" $keys[1] = "myTag2" $filter = New-Object Amazon.AutoScaling.Model.Filter $filter.Name = "key" $filter.Values = $keys Get-ASTag -Filter @( $filter )Example 3: This example describes all tags for all your Auto Scaling groups.
Get-ASTag-
For API details, see DescribeTags
in Amazon Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example describes the tags with a key value of either 'myTag' or 'myTag2'. The possible values for the filter name are 'auto-scaling-group', 'key', 'value', and 'propagate-at-launch'. The syntax used by this example requires PowerShell version 3 or later.
Get-ASTag -Filter @( @{ Name="key"; Values=@("myTag", "myTag2") } )Output:
Key : myTag2 PropagateAtLaunch : True ResourceId : my-asg ResourceType : auto-scaling-group Value : myTagValue2 Key : myTag PropagateAtLaunch : True ResourceId : my-asg ResourceType : auto-scaling-group Value : myTagValueExample 2: With PowerShell version 2, you must use New-Object to create the filter for the Filter parameter.
$keys = New-Object string[] 2 $keys[0] = "myTag" $keys[1] = "myTag2" $filter = New-Object Amazon.AutoScaling.Model.Filter $filter.Name = "key" $filter.Values = $keys Get-ASTag -Filter @( $filter )Example 3: This example describes all tags for all your Auto Scaling groups.
Get-ASTag-
For API details, see DescribeTags
in Amazon Tools for PowerShell Cmdlet Reference (V5).
-
For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.