How to create an Ec2 instance with a public IP address automatically ** without ** an Elastic IP announcement in the cloud?

In AWS cloud information, is there a way to declare an EC2 instance in a VPC with an open IP address without the need to declare Elastic IP and attach to it?

In AWS :: AutoScaling :: LaunchConfiguration, you can add the "AssociatePublicIpAddress" property to say that the instances automatically take on a public IP address. I am looking for an equivalent for AWS :: EC2 :: Instance

The following is a cloud fragment for creating an EC2 instance. I cannot have a single document that mentions how to add a public IP address without first declaring Elastic IP.

"MyEc2Instance": { "Type": "AWS::EC2::Instance", "Properties": { "IamInstanceProfile": { "Ref": "MyEc2InstanceProfile" }, "ImageId": { "Fn::FindInMap": [ "MyEc2Box", { "Ref": "Region" }, "ImageId" ] }, "InstanceType": { "Fn::FindInMap": [ "MyEc2Box", { "Ref": "Region" }, "InstanceType" ] }, "KeyName": { "Ref": "DefaultKeyPair" }, "Monitoring": "true", "SecurityGroupIds": [ { "Ref": "MyEc2SecurityGroup" } ], "SubnetId": { "Ref": "MyBoxSubnet" }, "Tags": [ { "Key": "Name", "Value": "MyBox" }, ] } }, 
+8
amazon-web-services amazon-cloudformation
source share
2 answers

Assuming you run your instance on a public VPC subnet (i.e., on a subnet with a routing table, including a rule for sending traffic to 0.0.0.0/0 to the Internet gateway), simply define the AssociatePublicIpAddress property in the NetworkInterfaces group of your EC2 resource:

  "NetworkInterfaces" : [{ "AssociatePublicIpAddress" : "True", "DeleteOnTermination" : "True", "SubnetId" : { "Ref" : "PublicSubnet" }, "DeviceIndex" : "0", "GroupSet" : [ { "Ref" : "SecurityGroup" } ] }], 

See the documentation at http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-network-iface-embedded.html.

If you run your instance on an EC2 Classic network (not VPC), it will automatically receive a public IP address.

+15
source share

I see that this is an old post, but I am posting an answer anyway, this may be useful. On the subnet, you can set: "MapPublicIpOnLaunch" to True, so the entire instance of this subnet will have a public IP address.

 MapPublicIpOnLaunch Indicates whether instances that are launched in this subnet receive a public IP address. By default, the value is false. Required: No Type: Boolean Update requires: No interruption. 
+4
source share

All Articles