AWS Tools for Windows PowerShell
Command Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Synopsis

Invokes the RunInstances operation against Amazon Elastic Compute Cloud.

Syntax

New-EC2Instance
-ImageId <String>
-AssociatePublicIp <Nullable<Boolean>>
-MinCount <Int32>
-MaxCount <Int32>
-KeyName <String>
-SecurityGroup <String[]>
-SecurityGroupId <String[]>
-UserData <String>
-UserDataFile <String>
-EncodeUserData <SwitchParameter>
-InstanceType <InstanceType>
-AvailabilityZone <String>
-Affinity <String>
-PlacementGroup <String>
-Tenancy <Tenancy>
-HostId <String>
-KernelId <String>
-RamdiskId <String>
-BlockDeviceMapping <BlockDeviceMapping[]>
-Monitoring_Enabled <Nullable<Boolean>>
-SubnetId <String>
-DisableApiTermination <Nullable<Boolean>>
-InstanceInitiatedShutdownBehavior <ShutdownBehavior>
-PrivateIpAddress <String>
-ClientToken <String>
-NetworkInterface <InstanceNetworkInterfaceSpecification[]>
-EbsOptimized <Nullable<Boolean>>
-InstanceProfile_Arn <String>
-InstanceProfile_Name <String>
-AdditionalInfo <String>
-Force <SwitchParameter>

Description

Launches a specified number of instances of an AMI for which you have permissions.

Parameters

-AdditionalInfo <String>
Reserved for internal use.
Required?False
Position?Named
Accept pipeline input?False
-Affinity <String>
The affinity setting for the instance on the dedicated host.
Required?False
Position?Named
Accept pipeline input?False
-AssociatePublicIp <Nullable<Boolean>>
Indicates whether to assign a public IP address to an instance in a VPC.
Required?False
Position?Named
Accept pipeline input?False
-AvailabilityZone <String>
The Availability Zone for the instance.
Required?False
Position?Named
Accept pipeline input?False
-BlockDeviceMapping <BlockDeviceMapping[]>
The block device mapping for the instance. For more information, see Block Device Mapping in the Amazon Elastic Compute Cloud User Guide.
Required?False
Position?Named
Accept pipeline input?False
-ClientToken <String>
Unique, case-sensitive identifier you provide to ensure idempotency of the request. For more information, see How to Ensure Idempotency in the Amazon Elastic Compute Cloud User Guide. Constraints: Maximum 64 ASCII characters
Required?False
Position?Named
Accept pipeline input?False
-DisableApiTermination <Nullable<Boolean>>
If you enable this option, you can't terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can. If you specify this option and then later want to be able to terminate the instance, you must first change the value of the disableApiTermination attribute to false using Edit-EC2InstanceAttribute. Alternatively, if you set -InstanceInitiatedShutdownBehavior to 'terminate', you can terminate the instance by running the shutdown command from the instance.
Required?False
Position?Named
Accept pipeline input?False
-EbsOptimized <Nullable<Boolean>>
Enables Amazon EBS optimization for the instance. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal Amazon EBS I/O performance. This option isn't available with all instance types. Additional usage charge apply when using this option.Default: false (disabled)
Required?False
Position?Named
Accept pipeline input?False
-EncodeUserData <SwitchParameter>
If set and the -UserData or -UserDataFile parameters are specified, the specified user data is base64 encoded prior to submitting to EC2. By default the user data is assumed to be encoded prior to being supplied to the cmdlet.
Required?False
Position?Named
Accept pipeline input?False
-Force <SwitchParameter>
This parameter overrides confirmation prompts to force the cmdlet to continue its operation. This parameter should always be used with caution.
Required?False
Position?Named
Accept pipeline input?False
-HostId <String>
The ID of the dedicted host on which the instance resides.
Required?False
Position?Named
Accept pipeline input?False
-ImageId <String>
The ID of the AMI to launch. The set of available AMI IDs can be determined using the Get-EC2Image or Get-EC2ImageByName cmdlets.
Required?True
Position?1
Accept pipeline input?True (ByValue, ByPropertyName)
-InstanceInitiatedShutdownBehavior <ShutdownBehavior>
Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).Valid values: stop | terminate. Default: stop.
Required?False
Position?Named
Accept pipeline input?False
-InstanceProfile_Arn <String>
The ARN of an IAM instance profile to associate with the instances.
Required?False
Position?Named
Accept pipeline input?False
-InstanceProfile_Name <String>
The name of an IAM instance profile to associate with the instances.
Required?False
Position?Named
Accept pipeline input?False
-InstanceType <InstanceType>
The instance type. For more information, see Instance Types in the Amazon Elastic Compute Cloud User Guide.Default: Amazon EC2 will use an m1.small instance if not specified.
Required?False
Position?Named
Accept pipeline input?False
-KernelId <String>
The ID of the kernel for the instance.Important: We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB in the Amazon Elastic Compute Cloud User Guide.
Required?False
Position?Named
Accept pipeline input?False
-KeyName <String>
The name of the key pair to use to connect to the instance using remote desktop or SSH.
Required?False
Position?Named
Accept pipeline input?False
-MaxCount <Int32>
The maximum number of instances to launch. If you specify a maximum that is more instances than Amazon EC2 can launch in the target Availability Zone EC2 will try to launch the maximum number for the target Availability Zone, but launches no fewer than the minimum number. Constraints: Between 1 and the maximum number you're allowed for the specified instance type. For more information about the default limits, and how to request an increase, see How many instances can I run in Amazon EC2 in the Amazon EC2 General FAQ. Default: 1.
Required?False
Position?Named
Accept pipeline input?False
-MinCount <Int32>
The minimum number of instances to launch. If you specify a minimum that is more instances than Amazon EC2 can launch in the target Availability Zone, Amazon EC2 launches no instances. Constraints: Between 1 and the maximum number you're allowed for the specified instance type. For more information about the default limits, and how to request an increase, see How many instances can I run in Amazon EC2 in the Amazon EC2 General FAQ. Default: 1.
Required?False
Position?Named
Accept pipeline input?False
-Monitoring_Enabled <Nullable<Boolean>>
Enables monitoring for the instance.
Required?False
Position?Named
Accept pipeline input?False
A set of one or more existing network interfaces to attach to the instance.
Required?False
Position?Named
Accept pipeline input?False
-PlacementGroup <String>
The name of an existing placement group.
Required?False
Position?Named
Accept pipeline input?False
-PrivateIpAddress <String>
[EC2-VPC] The primary private IP address. You must specify a value from the IP address range of the subnet. If not specified EC2 will assign an IP address from the IP address range of the subnet.
Required?False
Position?Named
Accept pipeline input?False
-RamdiskId <String>
The ID of the RAM disk.Important: We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB in the Amazon Elastic Compute Cloud User Guide.
Required?False
Position?Named
Accept pipeline input?False
-SecurityGroup <String[]>
The names of one or more security groups. Note that for a nondefault VPC, you must specify the security group by ID using the SecurityGroupIds parameter instead. For EC2-Classic or a default VPC, you can specify the security group by name or ID.Default: Amazon EC2 uses the default security group
Required?False
Position?Named
Accept pipeline input?False
-SecurityGroupId <String[]>
The IDs of one or more security groups. Note that for a nondefault VPC, you must specify the security group by ID using this parameter. For EC2-Classic or a default VPC, you can specify the security group by name or ID.
Required?False
Position?Named
Accept pipeline input?False
-SubnetId <String>
[EC2-VPC] The ID of the subnet to launch the instance into.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Tenancy <Tenancy>
The tenancy of the instance (if the instance is running in a VPC). An instance with a tenancy of dedicated runs on single-tenant hardware.Valid Values: default | dedicated | host
Required?False
Position?Named
Accept pipeline input?False
-UserData <String>
The base64-encoded MIME user data for the instances. If the -EncodeUserData switch is also set, the value for this parameter can be supplied as normal ASCII text and will be base64-encoded by the cmdlet.
Required?False
Position?Named
Accept pipeline input?False
-UserDataFile <String>
The name of a file containing base64-encoded MIME user data for the instances. Using this parameter causes any value for the UserData parameter to be ignored. If the -EncodeUserData switch is also set, the contents of the file can be normal ASCII text and will be base64-encoded by the cmdlet.
Required?False
Position?Named
Accept pipeline input?False

Common Credential and Region Parameters

-AccessKey <String>
The AWS access key for the user account. This can be a temporary access key if the corresponding session token is supplied to the -SessionToken parameter.
Required? False
Position? Named
Accept pipeline input? False
-Credential <AWSCredentials>
An AWSCredentials object instance containing access and secret key information, and optionally a token for session-based credentials.
Required? False
Position? Named
Accept pipeline input? False
-ProfileLocation <String>

Used to specify the name and location of the ini-format credential file (shared with the AWS CLI and other AWS SDKs)

If this optional parameter is omitted this cmdlet will search the encrypted credential file used by the AWS SDK for .NET and AWS Toolkit for Visual Studio first. If the profile is not found then the cmdlet will search in the ini-format credential file at the default location: (user's home directory)\.aws\credentials. Note that the encrypted credential file is not supported on all platforms. It will be skipped when searching for profiles on Windows Nano Server, Mac, and Linux platforms.

If this parameter is specified then this cmdlet will only search the ini-format credential file at the location given.

As the current folder can vary in a shell or during script execution it is advised that you use specify a fully qualified path instead of a relative path.

Required? False
Position? Named
Accept pipeline input? False
-ProfileName <String>
The user-defined name of an AWS credentials or SAML-based role profile containing credential information. The profile is expected to be found in the secure credential file shared with the AWS SDK for .NET and AWS Toolkit for Visual Studio. You can also specify the name of a profile stored in the .ini-format credential file used with the AWS CLI and other AWS SDKs.
Required? False
Position? Named
Accept pipeline input? False
-NetworkCredential <PSCredential>
Used with SAML-based authentication when ProfileName references a SAML role profile. Contains the network credentials to be supplied during authentication with the configured identity provider's endpoint. This parameter is not required if the user's default network identity can or should be used during authentication.
Required? False
Position? Named
Accept pipeline input? False
-SecretKey <String>
The AWS secret key for the user account. This can be a temporary secret key if the corresponding session token is supplied to the -SessionToken parameter.
Required? False
Position? Named
Accept pipeline input? False
-SessionToken <String>
The session token if the access and secret keys are temporary session-based credentials.
Required? False
Position? Named
Accept pipeline input? False
-Region <String>
The system name of the AWS region in which the operation should be invoked. For example, us-east-1, eu-west-1 etc.
Required? False
Position? Named
Accept pipeline input? False
-EndpointUrl <String>

The endpoint to make the call against.

Note: This parameter is primarily for internal AWS use and is not required/should not be specified for normal usage. The cmdlets normally determine which endpoint to call based on the region specified to the -Region parameter or set as default in the shell (via Set-DefaultAWSRegion). Only specify this parameter if you must direct the call to a specific custom endpoint.

Required? False
Position? Named
Accept pipeline input? False

Inputs

You can pipe a String object to this cmdlet for the ImageId parameter.

Outputs

Reservation
This cmdlet returns an Amazon.EC2.Model.Reservation instance with the instances contained in the .Instances member. The service response (type Amazon.EC2.Model.RunInstancesResponse) is added to the cmdlet entry in the $AWSHistory stack.

Examples

Example 1

PS C:\> New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -InstanceType m3.medium -KeyName my-key-pair -SecurityGroup my-security-group
This example launches a single instance of the specified AMI in EC2-Classic or a default VPC.

Example 2

PS C:\> New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -SubnetId subnet-12345678 -InstanceType t2.micro -KeyName my-key-pair -SecurityGroupId sg-12345678
This example launches a single instance of the specified AMI in a VPC.

Example 3

PS C:\> $bdm = New-Object Amazon.EC2.Model.BlockDeviceMapping
PS C:\> $bdm.VirtualName = "ephemeral0"
PS C:\> $bdm.DeviceName = "/dev/sdf"

PS C:\> New-EC2Instance -ImageId ami-12345678 -BlockDeviceMapping $bdm ...
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.

Example 4

PS C:\> $ami = Get-EC2ImageByName WINDOWS_2012R2_BASE

PS C:\> New-EC2Instance -ImageId $ami.ImageId ...
To specify one of the current Windows AMIs, get its AMI ID using Get-EC2ImageByName. This example launches an instance from the current base AMI for Windows Server 2012 R2.

Example 5

PS C:\>New-EC2Instance -ImageId ami-1a2b3c4d -InstanceType m4.large -KeyName my-key-pair -SecurityGroupId sg-1a2b3c4d -AvailabilityZone us-west-1a -Tenancy host -HostID h-1a2b3c4d5e6f1a2b3
Launches an instance into the specified dedicated host environment.

Supported Version

AWS Tools for PowerShell: 2.x.y.z