AWS Tools for Windows PowerShell
User Guide (Version 1.0)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Did this page help you?  Yes | No |  Tell us about it...

Launch an Amazon EC2 Instance

This section uses the key pair and security groups created in the preceding sections, along with AMI IDs returned by Get-EC2Image, to launch an Amazon EC2 instance.

Important

If you launch an instance that is not within the Free Usage Tier, you are billed after you launch the instance and charged for the time that the instance is running even if it remains idle.

To launch a new Amazon EC2 instance:

The following command creates a single Amazon EC2 instance using AMI ami-269dbb63, a Microsoft Windows Server 2012 image. The instance type is t1.micro.

The key pair is the one created in Create an Amazon EC2 Key Pair.

The security group is the non-VPC security group created in Create an Amazon EC2 Security Group.

PS C:> New-EC2Instance -ImageId ami-269dbb63 -MinCount 1 -MaxCount 1 -KeyName myPSKeyPair -SecurityGroupId sg-9cf9e5d9 -InstanceType t1.micro

ReservationId   : r-b70a0ef1
OwnerId         : 455364113843
RequesterId     :
GroupId         : {sg-9cf9e5d9}
GroupName       : {myPSSecurityGroup}
RunningInstance : {}

To launch a new Amazon EC2 instance in a VPC:

The following command creates a single Amazon EC2 instance in the private subnet specified by subnet-d60013bf. The command uses Amazon machine images ID ami-7454c344, a Microsoft Windows Server 2012 image. The instance type is t1.micro.

The key pair is the one created in the topic Create an Amazon EC2 Key Pair.

The security group, sg-5d293231, must be created in the VPC that contains the specified subnet, subnet-d60013bf. For more information about creating this security group, see Create an Amazon EC2 Security Group.

You can view your VPCs and associated subnets using the AWS Management Console or the AWS Toolkit for Visual Studio.

PS C:> PS C:\Windows> New-EC2Instance -ImageId ami-7454c344 -MinCount 1 -MaxCount 1 -KeyName myPSKeyPair -SecurityGroupId sg-5d293231 -InstanceType t1.micro -SubnetId subnet-d60013bf

To view the new Amazon EC2 instance:

After a few minutes, the instance will be up and running. Use the Get-EC2Instance cmdlet to retrieve information about the instance.

The Get-EC2Instance cmdlet returns a collection of Reservation instances. Each of these instances is itself a collection of RunningInstance (Amazon EC2) objects. Each invocation of New-EC2Instance creates a new Reservation instance. The Reservation instance contains one or more RunningInstance objects depending on the values you specified for the min and max parameters of New-EC2Instance.

The following example assigns the Reservation collection to a variable and then displays information for the first RunningInstance object in the first Reservation instance (index 0 for each collection). This example assumes that the instance launched previously is the only instance running in your account.

PS C:> $reservations = Get-EC2Instance
PS C:> $reservations[0].RunningInstance[0]


InstanceId            : i-f06e0ea9
ImageId               : ami-269dbb63
InstanceState         : Amazon.EC2.Model.InstanceState
PrivateDnsName        : ip-10-196-24-80.us-west-1.compute.internal
PublicDnsName         : ec2-54-241-88-135.us-west-1.compute.amazonaws.com
StateTransitionReason :
KeyName               : myPSKeyPair
AmiLaunchIndex        : 0
ProductCodes          : {}
InstanceType          : t1.micro
LaunchTime            : 2012-11-25T02:30:59.000Z
Placement             : Amazon.EC2.Model.Placement
KernelId              :
RamdiskId             :
Platform              : windows
Monitoring            : Amazon.EC2.Model.Monitoring
SubnetId              :
VpcId                 :
PrivateIpAddress      : 10.196.24.80
IpAddress             : 54.241.88.135
SourceDestCheck       : False
GroupId               : {sg-9cf9e5d9}
GroupName             : {myPSSecurityGroup}
StateReason           :
Architecture          : x86_64
RootDeviceType        : ebs
RootDeviceName        : /dev/sda1
BlockDeviceMapping    : {/dev/sda1}
InstanceLifecycle     :
SpotInstanceRequestId :
License               :
VirtualizationType    : hvm
ClientToken           :
Tag                   : {}
NetworkInterfaceSet   : {}
EbsOptimized          : False
InstanceProfile       :