View a markdown version of this page

搭配使用 CreateOrUpdateTags 與 CLI - Amazon EC2 Auto Scaling

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

搭配使用 CreateOrUpdateTags 與 CLI

下列程式碼範例示範如何使用 CreateOrUpdateTags

CLI
AWS CLI

為 Auto Scaling 群組中建立或更新標籤

此範例將兩個標籤新增至指定的 Auto Scaling 群組。

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

此命令不會產生輸出。

如需詳細資訊,請參閱《Amazon EC2 Auto Scaling 使用者指南》中的標記 Auto Scaling 群組和執行個體

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 CreateOrUpdateTags

PowerShell
Tools for PowerShell V4

範例 1:此範例將單一標籤新增至指定的 Auto Scaling 群組。標籤索引鍵為 'myTag',標籤值為 'myTagValue'。Auto Scaling 會將此標籤傳播到 Auto Scaling 群組啟動的後續 EC2 執行個體。此範例使用的語法需要 PowerShell 版本 3 或更新版本。

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

範例 2:使用 PowerShell 版本 2 時,必須使用 New-Object 來建立 Tag 參數的標籤。

$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
  • 如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》中的 CreateOrUpdateTags

Tools for PowerShell V5

範例 1:此範例將單一標籤新增至指定的 Auto Scaling 群組。標籤索引鍵為 'myTag',標籤值為 'myTagValue'。Auto Scaling 會將此標籤傳播到 Auto Scaling 群組啟動的後續 EC2 執行個體。此範例使用的語法需要 PowerShell 版本 3 或更新版本。

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

範例 2:使用 PowerShell 版本 2 時,必須使用 New-Object 來建立 Tag 參數的標籤。

$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
  • 如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》中的 CreateOrUpdateTags

如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 搭配 AWS SDK 使用此服務。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。