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>
-MaintenanceOptions_AutoRecovery <InstanceAutoRecoveryState>
-Placement_AvailabilityZone <String>
-BlockDeviceMapping <BlockDeviceMapping[]>
-CapacityReservationTarget_CapacityReservationId <String>
-CapacityReservationSpecification_CapacityReservationPreference <CapacityReservationPreference>
-CapacityReservationTarget_CapacityReservationResourceGroupArn <String>
-HibernationOptions_Configured <Boolean>
-CreditSpecification_CpuCredit <String>
-CpuOption <CpuOptionsRequest>
-DisableApiStop <Boolean>
-DisableApiTermination <Boolean>
-EbsOptimized <Boolean>
-ElasticGpuSpecification <ElasticGpuSpecification[]>
-ElasticInferenceAccelerator <ElasticInferenceAccelerator[]>
-EnclaveOptions_Enabled <Boolean>
-EnablePrimaryIpv6 <Boolean>
-PrivateDnsNameOptions_EnableResourceNameDnsAAAARecord <Boolean>
-PrivateDnsNameOptions_EnableResourceNameDnsARecord <Boolean>
-Placement_GroupId <String>
-Placement_GroupName <String>
-Placement_HostId <String>
-PrivateDnsNameOptions_HostnameType <HostnameType>
-Placement_HostResourceGroupArn <String>
-MetadataOptions_HttpEndpoint <InstanceMetadataEndpointState>
-MetadataOptions_HttpProtocolIpv6 <InstanceMetadataProtocolState>
-MetadataOptions_HttpPutResponseHopLimit <Int32>
-MetadataOptions_HttpToken <HttpTokensState>
-InstanceInitiatedShutdownBehavior <ShutdownBehavior>
-InstanceMarketOption <InstanceMarketOptionsRequest>
-MetadataOptions_InstanceMetadataTag <InstanceMetadataTagsState>
-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>
-ClientConfig <AmazonEC2Config>

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:
  • 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.
  • 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. For troubleshooting, see What to do if an instance immediately terminates, and Troubleshooting connecting to your instance.

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, which defines the EBS volumes and instance store volumes to attach to the instance at launch. For more information, see Block device mappings in the Amazon EC2 User Guide.
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 in which to run the instance.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCapacityReservationSpecification_CapacityReservationTarget_CapacityReservationId
-CapacityReservationTarget_CapacityReservationResourceGroupArn <String>
The ARN of the Capacity Reservation resource group in which to run the instance.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCapacityReservationSpecification_CapacityReservationTarget_CapacityReservationResourceGroupArn
-ClientConfig <AmazonEC2Config>
Amazon.PowerShell.Cmdlets.EC2.AmazonEC2ClientCmdlet.ClientConfig
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-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 Optimize CPU options in the Amazon EC2 User Guide.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCpuOptions
-CreditSpecification_CpuCredit <String>
The credit option for CPU usage of a T instance.Valid values: standard | unlimited
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesCpuCredit, CreditSpecification_CpuCredits
-DisableApiStop <Boolean>
Indicates whether an instance is enabled for stop protection. For more information, see Stop protection.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-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[]>
Deprecated.Amazon Elastic Graphics reached end of life on January 8, 2024. For workloads that require graphics acceleration, we recommend that you use Amazon EC2 G4ad, G4dn, or G5 instances.
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.Starting April 15, 2023, Amazon Web Services will not onboard new customers to Amazon Elastic Inference (EI), and will help current customers migrate their workloads to options that offer better price and performance. After April 15, 2023, new customers will not be able to launch instances with Amazon EI accelerators in Amazon SageMaker, Amazon ECS, or Amazon EC2. However, customers who have used Amazon EI at least once during the past 30-day period are considered current customers and will be able to continue using the service.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesElasticInferenceAccelerators
-EnablePrimaryIpv6 <Boolean>
If you’re launching an instance into a dual-stack or IPv6-only subnet, you can enable assigning a primary IPv6 address. A primary IPv6 address is an IPv6 GUA address associated with an ENI that you have enabled to use a primary IPv6 address. Use this option if an instance relies on its IPv6 address not changing. When you launch the instance, Amazon Web Services will automatically assign an IPv6 address associated with the ENI attached to your instance to be the primary IPv6 address. Once you enable an IPv6 GUA address to be a primary IPv6, you cannot disable it. When you enable an IPv6 GUA address to be a primary IPv6, the first IPv6 GUA will be made the primary IPv6 address until the instance is terminated or the network interface is detached. If you have multiple IPv6 addresses associated with an ENI attached to your instance and you enable a primary IPv6 address, the first IPv6 GUA address associated with the ENI becomes the primary IPv6 address.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-EnclaveOptions_Enabled <Boolean>
To enable the instance for Amazon Web Services Nitro Enclaves, set this parameter to true.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-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>
Set to true to enable your instance for hibernation.For Spot Instances, if you set Configured to true, either omit the InstanceInterruptionBehavior parameter (for SpotMarketOptions), or set it to hibernate. When Configured is true:
  • If you omit InstanceInterruptionBehavior, it defaults to hibernate.
  • If you set InstanceInterruptionBehavior to a value other than hibernate, you'll get an error.
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 EC2 User Guide.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv6Address <InstanceIpv6Address[]>
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>
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 EC2 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
-MaintenanceOptions_AutoRecovery <InstanceAutoRecoveryState>
Disables the automatic recovery behavior of your instance or sets it to default. For more information, see Simplified automatic recovery.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-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>
Enables or disables the HTTP metadata endpoint on your instances.If you specify a value of disabled, you cannot access your instance metadata.Default: enabled
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-MetadataOptions_HttpProtocolIpv6 <InstanceMetadataProtocolState>
Enables or disables the IPv6 endpoint for the instance metadata service.Default: disabled
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>
Indicates whether IMDSv2 is required.
  • optional - IMDSv2 is optional. You can choose whether to send a session token in your instance metadata retrieval requests. If you retrieve IAM role credentials without a session token, you receive the IMDSv1 role credentials. If you retrieve IAM role credentials using a valid session token, you receive the IMDSv2 role credentials.
  • required - IMDSv2 is required. You must send a session token in your instance metadata retrieval requests. With this option, retrieving the IAM role credentials always returns IMDSv2 credentials; IMDSv1 credentials are not available.
Default: If the value of ImdsSupport for the Amazon Machine Image (AMI) for your instance is v2.0, the default is required.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesMetadataOptions_HttpTokens
-MetadataOptions_InstanceMetadataTag <InstanceMetadataTagsState>
Set to enabled to allow access to instance tags from the instance metadata. Set to disabled to turn off access to instance tags from the instance metadata. For more information, see Work with instance tags using the instance metadata.Default: disabled
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesMetadataOptions_InstanceMetadataTags
-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 CreateFleet or ImportInstance.
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 for CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAvailabilityZone
-Placement_GroupId <String>
The ID of the placement group that the instance is in. If you specify GroupId, you can't specify GroupName.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_GroupName <String>
The name of the placement group that the instance is in. If you specify GroupName, you can't specify GroupId.
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 CreateFleet or ImportInstance.
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 this parameter, either omit the Tenancy parameter or set it to host.This parameter is not supported for CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_PartitionNumber <Int32>
The number of the partition that the instance is in. Valid only if the placement group strategy is set to partition.This parameter is not supported for CreateFleet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_SpreadDomain <String>
Reserved for future use.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Placement_Tenancy <Tenancy>
The tenancy of the instance. An instance with a tenancy of dedicated runs on single-tenant hardware.This parameter is not supported for CreateFleet. The host tenancy is not supported for ImportInstance or for T3 instances that are configured for the unlimited CPU credit option.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesTenancy
-PrivateDnsNameOptions_EnableResourceNameDnsAAAARecord <Boolean>
Indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-PrivateDnsNameOptions_EnableResourceNameDnsARecord <Boolean>
Indicates whether to respond to DNS queries for instance hostnames with DNS A records.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-PrivateDnsNameOptions_HostnameType <HostnameType>
The type of hostname for EC2 instances. For IPv4 only subnets, an instance DNS name must be based on the instance IPv4 address. For IPv6 only subnets, an instance DNS name must be based on the instance ID. For dual-stack subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-PrivateIpAddress <String>
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 Amazon Web Services 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 EC2 User Guide.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-SecurityGroup <String[]>
[Default VPC] The names of the security groups.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>
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 that are created during instance launch.You can specify tags for the following resources only:
  • Instances
  • Volumes
  • Spot Instance requests
  • Network interfaces
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

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

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

$bdm = New-Object Amazon.EC2.Model.BlockDeviceMapping
$bdm.VirtualName = "ephemeral0"
$bdm.DeviceName = "/dev/sdf"

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

$ami = Get-EC2ImageByName WINDOWS_2016_BASE

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 2016.

Example 5

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

$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
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