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.
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>
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. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | BlockDeviceMappings |
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) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | CapacityReservationSpecification_CapacityReservationTarget_CapacityReservationId |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | CapacityReservationSpecification_CapacityReservationTarget_CapacityReservationResourceGroupArn |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | CpuOptions |
standard
| unlimited
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | CpuCredit, CreditSpecification_CpuCredits |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
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) |
false
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | ElasticInferenceAccelerators |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
true
. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
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:InstanceInterruptionBehavior
, it defaults to hibernate
.InstanceInterruptionBehavior
to a value other than hibernate
, you'll get an error.false
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | InstanceProfile_Arn |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | InstanceProfile_Id, InstanceProfile_Name |
Required? | False |
Position? | 1 |
Accept pipeline input? | True (ByValue, ByPropertyName) |
stop
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
hibernate
or stop
. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | InstanceMarketOptions |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | Ipv6Addresses |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | LicenseSpecifications |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
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) |
disabled
, you cannot access your instance metadata.Default: enabled
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
optional
(in other words, set the use of IMDSv2 to optional
) or required
(in other words, set the use of IMDSv2 to required
).optional
- When IMDSv2 is optional, you can choose to retrieve instance metadata with or without a session token in your request. If you retrieve the IAM role credentials without a token, the IMDSv1 role credentials are returned. If you retrieve the IAM role credentials using a valid session token, the IMDSv2 role credentials are returned.required
- When IMDSv2 is required, you must send a session token with any instance metadata retrieval requests. In this state, retrieving the IAM role credentials always returns IMDSv2 credentials; IMDSv1 credentials are not available.optional
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | MetadataOptions_HttpTokens |
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) |
Aliases | MetadataOptions_InstanceMetadataTags |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | Monitoring_Enabled |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | NetworkInterfaces, NetworkInterfaceSet |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | Affinity |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | AvailabilityZone |
GroupId
, you can't specify GroupName
. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
GroupName
, you can't specify GroupId
. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | PlacementGroup |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | HostId, Placement_Host |
host
.This parameter is not supported for CreateFleet. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
partition
.This parameter is not supported for CreateFleet. Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
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) |
Aliases | Tenancy |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | SecurityGroups |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | SecurityGroupIds |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | TagSpecifications |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | AK |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByValue, ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByValue, ByPropertyName) |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | AWSProfilesLocation, ProfilesLocation |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | StoredCredentials, AWSProfileName |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | RegionToCall |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | SK, SecretAccessKey |
Required? | False |
Position? | Named |
Accept pipeline input? | True (ByPropertyName) |
Aliases | ST |
New-EC2Instance -ImageId ami-12345678 -MinCount 1 -MaxCount 1 -InstanceType m3.medium -KeyName my-key-pair -SecurityGroup my-security-groupThis 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 -SubnetId subnet-12345678 -InstanceType t2.micro -KeyName my-key-pair -SecurityGroupId sg-12345678This example launches a single instance of the specified AMI in a VPC.
$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.
$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.
New-EC2Instance -ImageId ami-1a2b3c4d -InstanceType m4.large -KeyName my-key-pair -SecurityGroupId sg-1a2b3c4d -AvailabilityZone us-west-1a -Tenancy host -HostID h-1a2b3c4d5e6f1a2b3Launches an instance into the specified dedicated host environment.
$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).
AWS Tools for PowerShell: 2.x.y.z