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

标签 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

错误是:

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

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

谢谢阅读

最佳答案

从 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 

关于powershell - 如何在 PowerShell 中使用公共(public) IP 地址将 EC2 实例启动到 VPC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23830811/

相关文章:

amazon-web-services - AWS ElasticSearch即服务无法通过独立的KIBANA连接

amazon-ec2 - ECS/EKS 相对于直接 EC2 节省成本

amazon-web-services - AWS Glue 使用 Cli 安排作业

aws-cli - 如何向 aws appsync api 提供 graphql 模式的 blob?

amazon-ec2 - 如何将vmware镜像上传到ec2?

amazon-web-services - 如何在 AWS CLI 中设置默认配置文件的名称?

powershell - 使用 PSSession 和 Microsoft.Exchange.Management.PowerShell.SnapIn 时出错

amazon-web-services - 如何从给定的AWS Powershell cmdlet/别名检索所有数据?

powershell - 导入保存的 AzureRMContext 仍需要密码

powershell - 如何将外部DSC模块导入PowerShell环境?