Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch an EC2 instance into a VPC with a public IP address in PowerShell?

I have been trying to use the following script, but haven't been successful:

$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

The error is:

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

The problem is about the parameter -AssociatePublicIp without it, the script works.

Thanks for reading

like image 684
Evren Avatar asked Dec 20 '22 14:12

Evren


1 Answers

As of AWS PowerShell version 2.1.3.0, this bug has been corrected.

I was able to execute this script:

New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey -InstanceType `
t1.micro -SubnetId subnet-56738b33 -AssociatePublicIp $true 
like image 113
Evren Avatar answered Jan 13 '23 02:01

Evren