Use DeleteTags with a CLI
The following code examples show how to use DeleteTags.
- CLI
-
- Amazon CLI
-
Example 1: To delete a tag from a resource
The following
delete-tagsexample deletes the tagStack=Testfrom the specified image. When you specify both a value and a key name, the tag is deleted only if the tag's value matches the specified value.aws ec2 delete-tags \ --resourcesami-1234567890abcdef0\ --tagsKey=Stack,Value=TestIt's optional to specify the value for a tag. The following
delete-tagsexample deletes the tag with the key namepurposefrom the specified instance, regardless of the tag value for the tag.aws ec2 delete-tags \ --resourcesi-1234567890abcdef0\ --tagsKey=purposeIf you specify the empty string as the tag value, the tag is deleted only if the tag's value is the empty string. The following
delete-tagsexample specifies the empty string as the tag value for the tag to delete.aws ec2 delete-tags \ --resourcesi-1234567890abcdef0\ --tagsKey=Name,Value=Example 2: To delete a tag from multiple resources
The following
delete-tagsexample deletes the tag``Purpose=Test`` from both an instance and an AMI. As shown in the previous example, you can omit the tag value from the command.aws ec2 delete-tags \ --resourcesi-1234567890abcdef0ami-1234567890abcdef0\ --tagsKey=Purpose-
For API details, see DeleteTags
in Amazon CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example deletes the specified tag from the specified resource, regardless of the tag value. The syntax used by this example requires PowerShell version 3 or later.
Remove-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag" } -ForceExample 2: This example deletes the specified tag from the specified resource, but only if the tag value matches. The syntax used by this example requires PowerShell version 3 or later.
Remove-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag";Value="myTagValue" } -ForceExample 3: This example deletes the specified tag from the specified resource, regardless of the tag value.
$tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "myTag" Remove-EC2Tag -Resource i-12345678 -Tag $tag -ForceExample 4: This example deletes the specified tag from the specified resource, but only if the tag value matches.
$tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "myTag" $tag.Value = "myTagValue" Remove-EC2Tag -Resource i-12345678 -Tag $tag -Force-
For API details, see DeleteTags
in Amazon Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example deletes the specified tag from the specified resource, regardless of the tag value. The syntax used by this example requires PowerShell version 3 or later.
Remove-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag" } -ForceExample 2: This example deletes the specified tag from the specified resource, but only if the tag value matches. The syntax used by this example requires PowerShell version 3 or later.
Remove-EC2Tag -Resource i-12345678 -Tag @{ Key="myTag";Value="myTagValue" } -ForceExample 3: This example deletes the specified tag from the specified resource, regardless of the tag value.
$tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "myTag" Remove-EC2Tag -Resource i-12345678 -Tag $tag -ForceExample 4: This example deletes the specified tag from the specified resource, but only if the tag value matches.
$tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "myTag" $tag.Value = "myTagValue" Remove-EC2Tag -Resource i-12345678 -Tag $tag -Force-
For API details, see DeleteTags
in Amazon Tools for PowerShell Cmdlet Reference (V5).
-
For a complete list of Amazon SDK developer guides and code examples, see Create Amazon EC2 resources using an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.