如何在 PowerShell 中使用公共 IP 地址将 EC2 实例启动到 VPC 中?

Evr*_*ren 4 powershell amazon-ec2 aws-cli aws-powershell

我一直在尝试使用以下脚本,但没有成功:

$Ami=Get-EC2ImageByName WINDOWS_2012_BASE

New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey -InstanceType `
t1.micro -SubnetId subnet-56738b33 -AssociatePublicIp $true
Run Code Online (Sandbox Code Playgroud)

错误是:

New-EC2Instance : Object reference not set to an instance of an object.
At line:1 char:1
+ New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Amazon.PowerShe...2InstanceCmdlet:NewEC2InstanceCmdlet)  
   [New-EC2Instance], InvalidOperationException
    + FullyQualifiedErrorId : System.NullReferenceException,Amazon.PowerShell.Cmdlets.EC2.NewEC2InstanceC 
   mdlet
Run Code Online (Sandbox Code Playgroud)

问题在于-AssociatePublicIp没有它的参数,脚本可以工作。

谢谢阅读

Evr*_*ren 5

从 AWS PowerShell 版本 2.1.3.0 开始,此错误已得到纠正。

我能够执行这个脚本:

New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey -InstanceType `
t1.micro -SubnetId subnet-56738b33 -AssociatePublicIp $true 
Run Code Online (Sandbox Code Playgroud)