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

Calls the Amazon Elastic Compute Cloud (EC2) RunInstances API operation.

Syntax

New-EC2Instance
-ImageId <String>
-AssociatePublicIp <Boolean>
-UserDataFile <String>
-EncodeUserData <SwitchParameter>
-AdditionalInfo <String>
-Placement_Affinity <String>
-IamInstanceProfile_Arn <String>
-Placement_AvailabilityZone <String>
-BlockDeviceMapping <BlockDeviceMapping[]>
-CapacityReservationTarget_CapacityReservationId <String>
-CapacityReservationSpecification_CapacityReservationPreference <CapacityReservationPreference>
-HibernationOptions_Configured <Boolean>
-CreditSpecification_CpuCredit <String>
-CpuOption <CpuOptionsRequest>
-DisableApiTermination <Boolean>
-EbsOptimized <Boolean>
-ElasticGpuSpecification <ElasticGpuSpecification[]>
-ElasticInferenceAccelerator <ElasticInferenceAccelerator[]>
-Placement_GroupName <String>
-Placement_HostId <String>
-Placement_HostResourceGroupArn <String>
-MetadataOptions_HttpEndpoint <InstanceMetadataEndpointState>
-MetadataOptions_HttpPutResponseHopLimit <Int32>
-MetadataOptions_HttpToken <HttpTokensState>
-InstanceInitiatedShutdownBehavior <ShutdownBehavior>
-InstanceMarketOption <InstanceMarketOptionsRequest>
-InstanceType <InstanceType>
-Ipv6AddressCount <Int32>
-Ipv6Address <InstanceIpv6Address[]>
-KernelId <String>
-KeyName <String>
-LaunchTemplate <LaunchTemplateSpecification>
-LicenseSpecification <LicenseConfigurationRequest[]>
-MaxCount <Int32>
-MinCount <Int32>
-Monitoring <Boolean>
-IamInstanceProfile_Name <String>
-NetworkInterface <InstanceNetworkInterfaceSpecification[]>
-Placement_PartitionNumber <Int32>
-PrivateIpAddress <String>
-RamdiskId <String>
-SecurityGroupId <String[]>
-SecurityGroup <String[]>
-Placement_SpreadDomain <String>
-SubnetId <String>
-TagSpecification <TagSpecification[]>
-Placement_Tenancy <Tenancy>
-UserData <String>
-ClientToken <String>
-Select <String>
-PassThru <SwitchParameter>
-Force <SwitchParameter>

Description

Launches the specified number of instances using an AMI for which you have permissions. You can specify a number of options, or leave the default options. The following rules apply:
  • [EC2-VPC] If you don't specify a subnet ID, we choose a default subnet from your default VPC for you. If you don't have a default VPC, you must specify a subnet ID in the request.
  • [EC2-Classic] If don't specify an Availability Zone, we choose one for you.
  • Some instance types must be launched into a VPC. If you do not have a default VPC, or if you do not specify a subnet ID, the request fails. For more information, see Instance Types Available Only in a VPC.
  • [EC2-VPC] All instances have a network interface with a primary private IPv4 address. If you don't specify this address, we choose one from the IPv4 range of your subnet.
  • Not all instance types support IPv6 addresses. For more information, see Instance Types.
  • If you don't specify a security group ID, we use the default security group. For more information, see Security Groups.
  • If any of the AMIs have a product code attached for which the user has not subscribed, the request fails.
You can create a launch template, which is a resource that contains the parameters to launch an instance. When you launch an instance using RunInstances, you can specify the launch template instead of specifying the launch parameters. To ensure faster instance launches, break up large requests into smaller batches. For example, create five separate launch requests for 100 instances each instead of one launch request for 500 instances. An instance is ready for you to use when it's in the running state. You can check the state of your instance using DescribeInstances. You can tag instances and EBS volumes during launch, after launch, or both. For more information, see CreateTags and Tagging Your Amazon EC2 Resources. Linux instances have access to the public key of the key pair at boot. You can use this key to provide secure access to the instance. Amazon EC2 public images use this feature to provide secure access without passwords. For more information, see Key Pairs in the Amazon Elastic Compute Cloud User Guide. For troubleshooting, see What To Do If An Instance Immediately Terminates, and Troubleshooting Connecting to Your Instance in the Amazon Elastic Compute Cloud User Guide.

Parameters

-AdditionalInfo <String>
Reserved.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-AssociatePublicIp <Boolean>
Indicates whether to assign a public IP address to an instance in a VPC.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-BlockDeviceMapping <BlockDeviceMapping[]>
The block device mapping entries.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesBlockDeviceMappings
-CapacityReservationSpecification_CapacityReservationPreference <CapacityReservationPreference>
Indicates the instance's Capacity Reservation preferences. Possible preferences include:
  • open - The instance can run in any open Capacity Reservation that has matching attributes (instance type, platform, Availability Zone).
  • none - The instance avoids running in a Capacity Reservation even if one is available. The instance runs as an On-Demand Instance.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-CapacityReservationTarget_CapacityReservationId <String>
The ID of the Capacity Reservation.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCapacityReservationSpecification_CapacityReservationTarget_CapacityReservationId
-ClientToken <String>
Unique, case-sensitive identifier you provide to ensure the idempotency of the request. If you do not specify a client token, a randomly generated token is used for the request to ensure idempotency.For more information, see Ensuring Idempotency.Constraints: Maximum 64 ASCII characters
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-CpuOption <CpuOptionsRequest>
The CPU options for the instance. For more information, see Optimizing CPU Options in the Amazon Elastic Compute Cloud User Guide.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCpuOptions
-CreditSpecification_CpuCredit <String>
The credit option for CPU usage of a T2 or T3 instance. Valid values are standard and unlimited.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCpuCredit, CreditSpecification_CpuCredits
-DisableApiTermination <Boolean>
If you set this parameter to true, you can't terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can. To change this attribute after launch, use ModifyInstanceAttribute. Alternatively, if you set InstanceInitiatedShutdownBehavior to terminate, you can terminate the instance by running the shutdown command from the instance.Default: false
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-EbsOptimized <Boolean>
Indicates whether the instance is optimized for Amazon EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal Amazon EBS I/O performance. This optimization isn't available with all instance types. Additional usage charges apply when using an EBS-optimized instance.Default: false
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-ElasticGpuSpecification <ElasticGpuSpecification[]>
An elastic GPU to associate with the instance. An Elastic GPU is a GPU resource that you can attach to your Windows instance to accelerate the graphics performance of your applications. For more information, see Amazon EC2 Elastic GPUs in the Amazon Elastic Compute Cloud User Guide.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-ElasticInferenceAccelerator <ElasticInferenceAccelerator[]>
An elastic inference accelerator to associate with the instance. Elastic inference accelerators are a resource you can attach to your Amazon EC2 instances to accelerate your Deep Learning (DL) inference workloads.You cannot specify accelerators from different generations in the same request.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesElasticInferenceAccelerators
-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?True (ByPropertyName)
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?True (ByPropertyName)
-HibernationOptions_Configured <Boolean>
If you set this parameter to true, your instance is enabled for hibernation.Default: false
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-IamInstanceProfile_Arn <String>
The Amazon Resource Name (ARN) of the instance profile.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesInstanceProfile_Arn
-IamInstanceProfile_Name <String>
The name of the instance profile.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesInstanceProfile_Id, InstanceProfile_Name
-ImageId <String>
The ID of the AMI. An AMI ID is required to launch an instance and must be specified here or in a launch template.
Required?False
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).Default: stop
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-InstanceMarketOption <InstanceMarketOptionsRequest>
The market (purchasing) option for the instances.For RunInstances, persistent Spot Instance requests are only supported when InstanceInterruptionBehavior is set to either hibernate or stop.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesInstanceMarketOptions
-InstanceType <InstanceType>
The instance type. For more information, see Instance Types in the Amazon Elastic Compute Cloud User Guide.Default: m1.small
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv6Address <InstanceIpv6Address[]>
[EC2-VPC] The IPv6 addresses from the range of the subnet to associate with the primary network interface. You cannot specify this option and the option to assign a number of IPv6 addresses in the same request. You cannot specify this option if you've specified a minimum number of instances to launch.You cannot specify this option and the network interfaces option in the same request.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesIpv6Addresses
-Ipv6AddressCount <Int32>
[EC2-VPC] The number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. You cannot specify this option and the option to assign specific IPv6 addresses in the same request. You can specify this option if you've specified a minimum number of instances to launch.You cannot specify this option and the network interfaces option in the same request.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-KernelId <String>
The ID of the kernel.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?True (ByPropertyName)
-KeyName <String>
The name of the key pair. You can create a key pair using CreateKeyPair or ImportKeyPair.If you do not specify a key pair, you can't connect to the instance unless you choose an AMI that is configured to allow users another way to log in.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-LaunchTemplate <LaunchTemplateSpecification>
The launch template to use to launch the instances. Any parameters that you specify in RunInstances override the same parameters in the launch template. You can specify either the name or ID of a launch template, but not both.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-LicenseSpecification <LicenseConfigurationRequest[]>
The license configurations.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesLicenseSpecifications
-MaxCount <Int32>
The maximum number of instances to launch. If you specify more instances than Amazon EC2 can launch in the target Availability Zone, Amazon EC2 launches the largest possible number of instances above MinCount.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 FAQ.If a value for this parameter is not specified the cmdlet will use a default value of '1'.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-MetadataOptions_HttpEndpoint <InstanceMetadataEndpointState>
This parameter enables or disables the HTTP metadata endpoint on your instances. If the parameter is not specified, the default state is enabled.If you specify a value of disabled, you will not be able to access your instance metadata.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-MetadataOptions_HttpPutResponseHopLimit <Int32>
The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further instance metadata requests can travel.Default: 1Possible values: Integers from 1 to 64
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-MetadataOptions_HttpToken <HttpTokensState>
The state of token usage for your instance metadata requests. If the parameter is not specified in the request, the default state is optional.If the state is optional, you can choose to retrieve instance metadata with or without a signed token header on your request. If you retrieve the IAM role credentials without a token, the version 1.0 role credentials are returned. If you retrieve the IAM role credentials using a valid signed token, the version 2.0 role credentials are returned.If the state is required, you must send a signed token header with any instance metadata retrieval requests. In this state, retrieving the IAM role credentials always returns the version 2.0 credentials; the version 1.0 credentials are not available.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesMetadataOptions_HttpTokens
-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.If a value for this parameter is not specified the cmdlet will use a default value of '1'.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Monitoring <Boolean>
Specifies whether detailed monitoring is enabled for the instance.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesMonitoring_Enabled
The network interfaces to associate with the instance. If you specify a network interface, you must specify any security groups and subnets as part of the network interface.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesNetworkInterfaces, NetworkInterfaceSet
-PassThru <SwitchParameter>
Changes the cmdlet behavior to return the value passed to the ImageId parameter. The -PassThru parameter is deprecated, use -Select '^ImageId' instead. This parameter will be removed in a future version.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_Affinity <String>
The affinity setting for the instance on the Dedicated Host. This parameter is not supported for the ImportInstance command.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAffinity
-Placement_AvailabilityZone <String>
The Availability Zone of the instance.If not specified, an Availability Zone will be automatically chosen for you based on the load balancing criteria for the Region.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAvailabilityZone
-Placement_GroupName <String>
The name of the placement group the instance is in.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesPlacementGroup
-Placement_HostId <String>
The ID of the Dedicated Host on which the instance resides. This parameter is not supported for the ImportInstance command.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesHostId, Placement_Host
-Placement_HostResourceGroupArn <String>
The ARN of the host resource group in which to launch the instances. If you specify a host resource group ARN, omit the Tenancy parameter or set it to host.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_PartitionNumber <Int32>
The number of the partition the instance is in. Valid only if the placement group strategy is set to partition.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_SpreadDomain <String>
Reserved for future use.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_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. The host tenancy is not supported for the ImportInstance command.This parameter is not supported by CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesTenancy
-PrivateIpAddress <String>
[EC2-VPC] The primary IPv4 address. You must specify a value from the IPv4 address range of the subnet.Only one private IP address can be designated as primary. You can't specify this option if you've specified the option to designate a private IP address as the primary IP address in a network interface specification. You cannot specify this option if you're launching more than one instance in the request.You cannot specify this option and the network interfaces option in the same request.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-RamdiskId <String>
The ID of the RAM disk to select. Some kernels require additional drivers at launch. Check the kernel requirements for information about whether you need to specify a RAM disk. To find kernel requirements, go to the AWS Resource Center and search for the kernel ID.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?True (ByPropertyName)
-SecurityGroup <String[]>
[EC2-Classic, default VPC] The names of the security groups. For a nondefault VPC, you must use security group IDs instead.If you specify a network interface, you must specify any security groups as part of the network interface.Default: Amazon EC2 uses the default security group.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesSecurityGroups
-SecurityGroupId <String[]>
The IDs of the security groups. You can create a security group using CreateSecurityGroup.If you specify a network interface, you must specify any security groups as part of the network interface.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesSecurityGroupIds
-Select <String>
Use the -Select parameter to control the cmdlet output. The default value is 'Reservation'. Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.EC2.Model.RunInstancesResponse). Specifying the name of a property of type Amazon.EC2.Model.RunInstancesResponse will result in that property being returned. Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-SubnetId <String>
[EC2-VPC] The ID of the subnet to launch the instance into.If you specify a network interface, you must specify any subnets as part of the network interface.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-TagSpecification <TagSpecification[]>
The tags to apply to the resources during launch. You can only tag instances and volumes on launch. The specified tags are applied to all instances or volumes that are created during launch. To tag a resource after it has been created, see CreateTags.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesTagSpecifications
-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?True (ByPropertyName)
-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?True (ByPropertyName)

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?True (ByPropertyName)
AliasesAK
-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?True (ByValue, ByPropertyName)
-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?True (ByPropertyName)
-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?True (ByValue, ByPropertyName)
-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.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?True (ByPropertyName)
AliasesAWSProfilesLocation, ProfilesLocation
-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?True (ByPropertyName)
AliasesStoredCredentials, AWSProfileName
-Region <Object>
The system name of an AWS region or an AWSRegion instance. This governs the endpoint that will be used when calling service operations. Note that the AWS resources referenced in a call are usually region-specific.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesRegionToCall
-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?True (ByPropertyName)
AliasesSK, SecretAccessKey
-SessionToken <String>
The session token if the access and secret keys are temporary session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesST

Outputs

This cmdlet returns an Amazon.EC2.Model.Reservation object. The service call response (type Amazon.EC2.Model.RunInstancesResponse) can also be referenced from properties attached 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.

Example 6

PS C:\> $tag1 = @{ Key="webserver"; Value="production" }
PS C:\> $tag2 = @{ Key="cost-center"; Value="cc123" }

PS C:\> $tagspec1 = new-object Amazon.EC2.Model.TagSpecification
PS C:\> $tagspec1.ResourceType = "instance"
PS C:\> $tagspec1.Tags.Add($tag1)

PS C:\> $tagspec2 = new-object Amazon.EC2.Model.TagSpecification
PS C:\> $tagspec2.ResourceType = "volume"
PS C:\> $tagspec2.Tags.Add($tag2)

New-EC2Instance -ImageId "ami-1a2b3c4d" -KeyName "my-key-pair" -MaxCount 2 -InstanceType "t2.large" -SubnetId "subnet-1a2b3c4d" -TagSpecification $tagspec1,$tagspec2
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).

Supported Version

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