本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭配使用 DeleteTags 與 CLI
下列程式碼範例示範如何使用 DeleteTags。
- CLI
-
- AWS CLI
-
從 Auto Scaling 群組刪除標籤
下列
delete-tags範例會從指定的 Auto Scaling 群組刪除指定的標籤。aws autoscaling delete-tags \ --tagsResourceId=my-asg,ResourceType=auto-scaling-group,Key=Dept,Value=Research此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon EC2 Auto Scaling 使用者指南》中的標記 Auto Scaling 群組和執行個體。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteTags
。
-
- PowerShell
-
- Tools for PowerShell V4
-
範例 1:此範例從指定的 Auto Scaling 群組中移除指定的標籤。在繼續操作之前,系統會提示您確認。此範例使用的語法需要 PowerShell 版本 3 或更新版本。
Remove-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag" } )輸出:
Confirm Are you sure you want to perform this action? Performing the operation "Remove-ASTag (DeleteTags)" on target "Amazon.AutoScaling.Model.Tag". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):範例 2:如果您指定強制參數,在繼續操作之前,系統不會提示您進行確認。
Remove-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag" } ) -Force範例 3:使用 Powershell 版本 2 時,必須使用 New-Object 來建立 Tag 參數的標籤。
$tag = New-Object Amazon.AutoScaling.Model.Tag $tag.ResourceType = "auto-scaling-group" $tag.ResourceId = "my-asg" $tag.Key = "myTag" Remove-ASTag -Tag $tag -Force-
如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》中的 DeleteTags。
-
- Tools for PowerShell V5
-
範例 1:此範例從指定的 Auto Scaling 群組中移除指定的標籤。在繼續操作之前,系統會提示您確認。此範例使用的語法需要 PowerShell 版本 3 或更新版本。
Remove-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag" } )輸出:
Confirm Are you sure you want to perform this action? Performing the operation "Remove-ASTag (DeleteTags)" on target "Amazon.AutoScaling.Model.Tag". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):範例 2:如果您指定強制參數,在繼續操作之前,系統不會提示您進行確認。
Remove-ASTag -Tag @( @{ResourceType="auto-scaling-group"; ResourceId="my-asg"; Key="myTag" } ) -Force範例 3:使用 Powershell 版本 2 時,必須使用 New-Object 來建立 Tag 參數的標籤。
$tag = New-Object Amazon.AutoScaling.Model.Tag $tag.ResourceType = "auto-scaling-group" $tag.ResourceId = "my-asg" $tag.Key = "myTag" Remove-ASTag -Tag $tag -Force-
如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》中的 DeleteTags。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 搭配 AWS SDK 使用此服務。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。