View a markdown version of this page

Use DescribeTags with a CLI - Amazon EC2 Auto Scaling
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 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-tags

Output:

{ "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 --filters option.

aws autoscaling describe-tags --filters Name=auto-scaling-group,Values=my-asg

For 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-items option.

aws autoscaling describe-tags \ --max-items 1

If the output includes a NextToken field, there are more tags. To get the additional tags, use the value of this field with the --starting-token option in a subsequent call as follows.

aws autoscaling describe-tags \ --filters Name=auto-scaling-group,Values=my-asg \ --starting-token Z3M3LMPEXAMPLE

For 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 : myTagValue

Example 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 : myTagValue

Example 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.