AWS ec2 documentation change
Summary
Added PowerShell V5 examples for launching EC2 instances with security groups, key pairs, dedicated hosts, tagging, and DryRun validation
Security assessment
Examples demonstrate security-related configurations (security groups, key pairs) but do not address a specific vulnerability. DryRun example shows permission validation, a security best practice.
Diff
diff --git a/ec2/latest/devguide/example_ec2_RunInstances_section.md b/ec2/latest/devguide/example_ec2_RunInstances_section.md index 6db1c9167..84b8ef359 100644 --- a//ec2/latest/devguide/example_ec2_RunInstances_section.md +++ b//ec2/latest/devguide/example_ec2_RunInstances_section.md @@ -795,0 +796,67 @@ PowerShell +**Tools for PowerShell V5** + + +**Example 1: This example launches a single instance of the specified AMI in EC2-Classic or a default VPC.** + + + New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -InstanceType m3.medium -KeyName my-key-pair -SecurityGroup my-security-group + + +**Example 2: This example launches a single instance of the specified AMI in a VPC.** + + + New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -SubnetId subnet-12345678 -InstanceType t2.micro -KeyName my-key-pair -SecurityGroupId sg-12345678 + + +**Example 3: To add an EBS volume or an instance store volume, define a block device mapping and add it to the command. This example adds an instance store volume.** + + + $bdm = New-Object Amazon.EC2.Model.BlockDeviceMapping + $bdm.VirtualName = "ephemeral0" + $bdm.DeviceName = "/dev/sdf" + + New-EC2Instance -ImageId ami-12345678 -BlockDeviceMapping $bdm ... + + +**Example 4: To specify one of the current Windows AMIs, get its AMI ID using Get-SSMLatestEC2Image. This example launches an instance from the current base AMI for Windows Server 2016.** + + + $ami = (Get-SSMLatestEC2Image -Path 'ami-windows-latest' -ImageName 'WINDOWS*2016*English*Core*BASE').Value + + New-EC2Instance -ImageId $ami ... + + +**Example 5: Launches an instance into the specified dedicated host environment.** + + + New-EC2Instance -ImageId ami-1a2b3c4d -InstanceType m4.large -KeyName my-key-pair -SecurityGroupId sg-1a2b3c4d -AvailabilityZone us-west-1a -Tenancy host -HostID h-1a2b3c4d5e6f1a2b3 + + +**Example 6: This request launches two instances and applies a tag with a key of webserver and a value of production to the instances. The request also applies a tag with a key of cost-center and a value of cc123 to the volumes that are created (in this case, the root volume for each instance).** + + + $tag1 = @{ Key="webserver"; Value="production" } + $tag2 = @{ Key="cost-center"; Value="cc123" } + + $tagspec1 = new-object Amazon.EC2.Model.TagSpecification + $tagspec1.ResourceType = "instance" + $tagspec1.Tags.Add($tag1) + + $tagspec2 = new-object Amazon.EC2.Model.TagSpecification + $tagspec2.ResourceType = "volume" + $tagspec2.Tags.Add($tag2) + + New-EC2Instance -ImageId "ami-1a2b3c4d" -KeyName "my-key-pair" -MaxCount 2 -InstanceType "t2.large" -SubnetId "subnet-1a2b3c4d" -TagSpecification $tagspec1,$tagspec2 + + +**Example 7: This example validates permissions for launching an EC2 instance using the DryRun parameter without actually creating the instance. Note: This throws an exception if succeeded which is the expected behavior.** + + + New-EC2Instance -ImageId 'ami-12345678' -InstanceType 't2.micro' -KeyName 'my-key-pair' -Region 'us-west-2' -DryRun $true + + + * For API details, see [RunInstances](https://docs.aws.amazon.com/powershell/v5/reference) in _AWS Tools for PowerShell Cmdlet Reference (V5)_. + + + +