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

Question:

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

The error is:


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

Thanks for reading

Answer:

I ran into the same problem, and a possible workaround while still using PowerShell is to create the network interface first, and then associating it with the instance:

The InstanceNetworkInterfaceSpecification has a property to indicate if the interface needs a public IP address (see the docs)

Source:

How to launch an EC2 instance into a VPC with a public IP address in PowerShell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply