AWS ec2 documentation change
Summary
Added PowerShell V5 examples for EC2 DescribeInstances API including instance querying, filtering, and dry-run validation
Security assessment
The changes add usage examples without addressing security vulnerabilities or introducing security features. Examples show instance metadata exposure but don't highlight security implications.
Diff
diff --git a/ec2/latest/devguide/example_ec2_DescribeInstances_section.md b/ec2/latest/devguide/example_ec2_DescribeInstances_section.md index 1098003b0..1d730b1e4 100644 --- a//ec2/latest/devguide/example_ec2_DescribeInstances_section.md +++ b//ec2/latest/devguide/example_ec2_DescribeInstances_section.md @@ -1080,0 +1081,161 @@ PowerShell +**Tools for PowerShell V5** + + +**Example 1: This example describes the specified instance.** + + + (Get-EC2Instance -InstanceId i-12345678).Instances + + +**Output:** + + + AmiLaunchIndex : 0 + Architecture : x86_64 + BlockDeviceMappings : {/dev/sda1} + ClientToken : TleEy1448154045270 + EbsOptimized : False + Hypervisor : xen + IamInstanceProfile : Amazon.EC2.Model.IamInstanceProfile + ImageId : ami-12345678 + InstanceId : i-12345678 + InstanceLifecycle : + InstanceType : t2.micro + KernelId : + KeyName : my-key-pair + LaunchTime : 12/4/2015 4:44:40 PM + Monitoring : Amazon.EC2.Model.Monitoring + NetworkInterfaces : {ip-10-0-2-172.us-west-2.compute.internal} + Placement : Amazon.EC2.Model.Placement + Platform : Windows + PrivateDnsName : ip-10-0-2-172.us-west-2.compute.internal + PrivateIpAddress : 10.0.2.172 + ProductCodes : {} + PublicDnsName : + PublicIpAddress : + RamdiskId : + RootDeviceName : /dev/sda1 + RootDeviceType : ebs + SecurityGroups : {default} + SourceDestCheck : True + SpotInstanceRequestId : + SriovNetSupport : + State : Amazon.EC2.Model.InstanceState + StateReason : + StateTransitionReason : + SubnetId : subnet-12345678 + Tags : {Name} + VirtualizationType : hvm + VpcId : vpc-12345678 + +**Example 2: This example describes all your instances in the current region, grouped by reservation. To see the instance details expand the Instances collection within each reservation object.** + + + Get-EC2Instance + + +**Output:** + + + GroupNames : {} + Groups : {} + Instances : {} + OwnerId : 123456789012 + RequesterId : 226008221399 + ReservationId : r-c5df370c + + GroupNames : {} + Groups : {} + Instances : {} + OwnerId : 123456789012 + RequesterId : 854251627541 + ReservationId : r-63e65bab + ... + +**Example 3: This example illustrates using a filter to query for EC2 instances in a specific subnet of a VPC.** + + + (Get-EC2Instance -Filter @{Name="vpc-id";Values="vpc-1a2bc34d"},@{Name="subnet-id";Values="subnet-1a2b3c4d"}).Instances + + +**Output:** + + + InstanceId InstanceType Platform PrivateIpAddress PublicIpAddress SecurityGroups SubnetId VpcId + ---------- ------------ -------- ---------------- --------------- -------------- -------- ----- + i-01af...82cf180e19 t2.medium Windows 10.0.0.98 ... subnet-1a2b3c4d vpc-1a2b3c4d + i-0374...7e9d5b0c45 t2.xlarge Windows 10.0.0.53 ... subnet-1a2b3c4d vpc-1a2b3c4d + +**Example 4: This example illustrates using a filter with multiple values to query for EC2 instances that are both running and stopped** + + + $InstanceParams = @{ + Filter = @( + @{'Name' = 'instance-state-name';'Values' = @("running","stopped")} + ) + } + + (Get-EC2Instance @InstanceParams).Instances + + +**Output:** + + + InstanceId InstanceType Platform PrivateIpAddress PublicIpAddress SecurityGroups SubnetId VpcId + ---------- ------------ -------- ---------------- --------------- -------------- -------- ----- + i-05a9...f6c5f46e18 t3.medium 10.0.1.7 ... subnet-1a2b3c4d vpc-1a2b3c4d + i-02cf...945c4fdd07 t3.medium Windows 10.0.1.8 ... subnet-1a2b3c4d vpc-1a2b3c4d + i-0ac0...c037f9f3a1 t3.xlarge Windows 10.0.1.10 ... subnet-1a2b3c4d vpc-1a2b3c4d + i-066b...57b7b08888 t3.medium Windows 10.0.1.11 ... subnet-1a2b3c4d vpc-1a2b3c4d + i-0fee...82e83ccd72 t3.medium Windows 10.0.1.5 ... subnet-1a2b3c4d vpc-1a2b3c4d + i-0a68...274cc5043b t3.medium Windows 10.0.1.6 ... subnet-1a2b3c4d vpc-1a2b3c4d + +**Example 5: This example illustrates using a filter with multiple values to query for EC2 instances that are both running and stopped and using the Select-Object cmdlet for choosing specific values to output.** + + + $InstanceParams = @{ + Filter = @( + @{'Name' = 'instance-state-name';'Values' = @("running","stopped")} + ) + } + + $SelectParams = @{ + Property = @( + "InstanceID", "InstanceType", "Platform", "PrivateIpAddress", + @{Name="Name";Expression={$_.Tags[$_.Tags.Key.IndexOf("Name")].Value}}, + @{Name="State";Expression={$_.State.Name}} + ) + } + + $result = Get-EC2Instance @InstanceParams + $result.Instances | Select-Object @SelectParams | Format-Table -AutoSize + + +**Output:** + + + InstanceId InstanceType Platform PrivateIpAddress Name State + ---------- ------------ -------- ---------------- ---- ----- + i-05a9...f6c5f46e18 t3.medium 10.0.1.7 ec2-name-01 running + i-02cf...945c4fdd07 t3.medium Windows 10.0.1.8 ec2-name-02 stopped + i-0ac0...c037f9f3a1 t3.xlarge Windows 10.0.1.10 ec2-name-03 running + i-066b...57b7b08888 t3.medium Windows 10.0.1.11 ec2-name-04 stopped + i-0fee...82e83ccd72 t3.medium Windows 10.0.1.5 ec2-name-05 running + i-0a68...274cc5043b t3.medium Windows 10.0.1.6 ec2-name-06 stopped + +**Example 6: This example validates permissions for getting EC2 instances 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-EC2Instance: Request would have succeeded, but DryRun flag is set. + + * For API details, see [DescribeInstances](https://docs.aws.amazon.com/powershell/v5/reference) in _AWS Tools for PowerShell Cmdlet Reference (V5)_. + + + +