View a markdown version of this page

Use DescribeTags with a CLI - AWS SDK Code Examples

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

Use DescribeTags with a CLI

The following code examples show how to use DescribeTags.

CLI
AWS 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 AWS 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 AWS 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 AWS Tools for PowerShell Cmdlet Reference (V5).