Use CreateOrUpdateTags with a CLI - Amazon EC2 Auto Scaling

Use CreateOrUpdateTags with a CLI

The following code examples show how to use CreateOrUpdateTags.

CLI
AWS CLI

To create or update tags for an Auto Scaling group

This example adds two tags to the specified Auto Scaling group.

aws autoscaling create-or-update-tags \ --tags ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Role,Value=WebServer,PropagateAtLaunch=true ResourceId=my-asg,ResourceType=auto-scaling-group,Key=Dept,Value=Research,PropagateAtLaunch=true

This command produces no output.

For more information, see Tagging Auto Scaling groups and instances in the Amazon EC2 Auto Scaling User Guide.

PowerShell
Tools for PowerShell V4

Example 1: This example adds a single tag to the specified Auto Scaling group. The tag key is 'myTag' and the tag value is 'myTagValue'. Auto Scaling propagates this tag to the subsequent EC2 instances launched by the Auto Scaling group. The syntax used by this example requires PowerShell version 3 or later.

Set-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag"; Value="myTagValue"; PropagateAtLaunch=$true} )

Example 2: With PowerShell version 2, you must use New-Object to create the tag for the Tag parameter.

$tag = New-Object Amazon.AutoScaling.Model.Tag $tag.ResourceType = "auto-scaling-group" $tag.ResourceId = "my-asg" $tag.Key = "myTag" $tag.Value = "myTagValue" $tag.PropagateAtLaunch = $true Set-ASTag -Tag $tag
  • For API details, see CreateOrUpdateTags in AWS Tools for PowerShell Cmdlet Reference (V4).

Tools for PowerShell V5

Example 1: This example adds a single tag to the specified Auto Scaling group. The tag key is 'myTag' and the tag value is 'myTagValue'. Auto Scaling propagates this tag to the subsequent EC2 instances launched by the Auto Scaling group. The syntax used by this example requires PowerShell version 3 or later.

Set-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag"; Value="myTagValue"; PropagateAtLaunch=$true} )

Example 2: With PowerShell version 2, you must use New-Object to create the tag for the Tag parameter.

$tag = New-Object Amazon.AutoScaling.Model.Tag $tag.ResourceType = "auto-scaling-group" $tag.ResourceId = "my-asg" $tag.Key = "myTag" $tag.Value = "myTagValue" $tag.PropagateAtLaunch = $true Set-ASTag -Tag $tag
  • For API details, see CreateOrUpdateTags in AWS Tools for PowerShell Cmdlet Reference (V5).

For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.