AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-06-28 · Documentation low

File: code-library/latest/ug/ec2_example_ec2_DescribeTags_section.md

Summary

Added PowerShell V5 examples for Get-EC2Tag including tag filtering, resource grouping, dry-run validation, and tag manipulation

Security assessment

Added example demonstrating DryRun parameter usage for permission validation, which helps users test security policies without making changes. No specific security vulnerability addressed.

Diff

diff --git a/code-library/latest/ug/ec2_example_ec2_DescribeTags_section.md b/code-library/latest/ug/ec2_example_ec2_DescribeTags_section.md
index e9e25edeb..fa2f8ddb4 100644
--- a//code-library/latest/ug/ec2_example_ec2_DescribeTags_section.md
+++ b//code-library/latest/ug/ec2_example_ec2_DescribeTags_section.md
@@ -257,0 +258,92 @@ PowerShell
+**Tools for PowerShell V5**
+    
+
+**Example 1: This example fetches the tags for resource-type 'image'**
+    
+    
+    Get-EC2Tag -Filter @{Name="resource-type";Values="image"}
+    
+
+**Output:**
+    
+    
+    Key         ResourceId            ResourceType Value
+    ---         ----------            ------------ -----
+    Name        ami-0a123b4ccb567a8ea image        Win7-Imported
+    auto-delete ami-0a123b4ccb567a8ea image        never
+
+**Example 2: This example fetches all the tags for all the resources and groups them by resource type**
+    
+    
+    Get-EC2Tag | Group-Object resourcetype
+    
+
+**Output:**
+    
+    
+    Count Name                      Group
+    ----- ----                      -----
+        9 subnet                    {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
+       53 instance                  {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
+        3 route-table               {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
+        5 security-group            {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
+       30 volume                    {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
+        1 internet-gateway          {Amazon.EC2.Model.TagDescription}
+        3 network-interface         {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
+        4 elastic-ip                {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
+        1 dhcp-options              {Amazon.EC2.Model.TagDescription}
+        2 image                     {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
+        3 vpc                       {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
+
+**Example 3: This example displays all the resources with tag 'auto-delete' with value 'no' for the given region**
+    
+    
+    Get-EC2Tag -Region eu-west-1 -Filter @{Name="tag:auto-delete";Values="no"}
+    
+
+**Output:**
+    
+    
+    Key         ResourceId            ResourceType Value
+    ---         ----------            ------------ -----
+    auto-delete i-0f1bce234d5dd678b   instance     no
+    auto-delete vol-01d234aa5678901a2 volume       no
+    auto-delete vol-01234bfb5def6f7b8 volume       no
+    auto-delete vol-01ccb23f4c5e67890 volume       no
+
+**Example 4: This example obtains all the resources with tag 'auto-delete' with 'no' value and further filters in the next pipe to parse only 'instance' resource types and eventually creates 'ThisInstance' tag for each instance resources with value being the instance id itself**
+    
+    
+    Get-EC2Tag -Region eu-west-1 -Filter @{Name="tag:auto-delete";Values="no"} | Where-Object ResourceType -eq "instance" | ForEach-Object {New-EC2Tag -ResourceId $_.ResourceId -Tag @{Key="ThisInstance";Value=$_.ResourceId}}
+    
+
+**Example 5: This example fetches tags for all the instance resources as well as 'Name' keys and displays them in a table format**
+    
+    
+    Get-EC2Tag -Filter @{Name="resource-type";Values="instance"},@{Name="key";Values="Name"} | Select-Object ResourceId, @{Name="Name-Tag";Expression={$PSItem.Value}} | Format-Table -AutoSize
+    
+
+**Output:**
+    
+    
+    ResourceId          Name-Tag
+    ----------          --------
+    i-012e3cb4df567e1aa jump1
+    i-01c23a45d6fc7a89f repro-3
+
+**Example 6: This example validates permissions for getting EC2 Tags using the DryRun parameter without actually fetching them. Note: This throws an exception if succeeded which is the expected behavior.**
+    
+    
+    Get-EC2Tag -DryRun $true
+    
+
+**Output:**
+    
+    
+    Get-EC2Tag: Request would have succeeded, but DryRun flag is set.
+
+  * For API details, see [DescribeTags](https://docs.aws.amazon.com/powershell/v5/reference) in _AWS Tools for PowerShell Cmdlet Reference (V5)_. 
+
+
+
+