EC2 Instances will not keep elastic IP
Asked Answered
S

3

5

So, I don't understand what is going on here... I have (3) Micro EC2 Instances which are launched (without elastic ip)

I then go to Network Security->Elastic IPs and click associate IP address. I chose a running EC2 instance, that instance then uses the elastic ip.

If I stop, then start this SAME ec2 instance, it doesnt have the same previous elastic IP address and is instead some completely new IP address. This is messing up scripts that then depend on the previously associated elastic ip to that EC2 instance.

Why is this happening and why cant i get any of the (3) instances to adopt and keep this assigned elastic ip?

Soracco answered 6/2, 2014 at 17:2 Comment(0)
A
3

Elastic IPs become disassociated with EC2 instances (in EC2-Classic) when you stop them. You will need to re-associate them again on startup, which can be done through the API (via AssociateAddress), CLI (via ec2-associate-address), or via the AWS Console.

Here's what the Elastic IP documentation has to say on the matter:

When you associate an EIP with an instance, the instance's current public IP address is released to the EC2-Classic public IP address pool. If you disassociate an EIP from the instance, the instance is automatically assigned a new public IP address within a few minutes. In addition, stopping the instance also disassociates the EIP from it.

We solve this at work by tagging our dev instances (which are turned off overnight) with the desired elastic IP and run a script in the morning to first turn them on, and then re-associate the elastic IP.

Anagoge answered 6/2, 2014 at 17:5 Comment(5)
Is there anyway to KEEP that IP address on stopping them?Soracco
@Soracco Not with AWS, but you could add a script that will run on instance start up to associate an ip address via command line tools or directly via APIAccuracy
@Accuracy Agreed. We solve this at work by tagging our dev instances (which are turned off overnight) with the desired elastic IP and run a script in the morning to first turn them on, and then re-associate the elastic IP.Anagoge
@HyperAnthony - great point, this is likely what ill have to do tooSoracco
@CodeTalk: the EIP address won't change because it's not being released from the account and cannot be reserved by someone else.Tegucigalpa
E
6

If you create a VPC and then re-provision the 3 micro instances under the VPC, EIPs you associate will remain associated during stop/start cycles. You won't be able to reuse your existing EC2 instances or EIPs; you'll have to recreate them under the new VPC.

Electro answered 6/2, 2014 at 17:11 Comment(0)
A
3

Elastic IPs become disassociated with EC2 instances (in EC2-Classic) when you stop them. You will need to re-associate them again on startup, which can be done through the API (via AssociateAddress), CLI (via ec2-associate-address), or via the AWS Console.

Here's what the Elastic IP documentation has to say on the matter:

When you associate an EIP with an instance, the instance's current public IP address is released to the EC2-Classic public IP address pool. If you disassociate an EIP from the instance, the instance is automatically assigned a new public IP address within a few minutes. In addition, stopping the instance also disassociates the EIP from it.

We solve this at work by tagging our dev instances (which are turned off overnight) with the desired elastic IP and run a script in the morning to first turn them on, and then re-associate the elastic IP.

Anagoge answered 6/2, 2014 at 17:5 Comment(5)
Is there anyway to KEEP that IP address on stopping them?Soracco
@Soracco Not with AWS, but you could add a script that will run on instance start up to associate an ip address via command line tools or directly via APIAccuracy
@Accuracy Agreed. We solve this at work by tagging our dev instances (which are turned off overnight) with the desired elastic IP and run a script in the morning to first turn them on, and then re-associate the elastic IP.Anagoge
@HyperAnthony - great point, this is likely what ill have to do tooSoracco
@CodeTalk: the EIP address won't change because it's not being released from the account and cannot be reserved by someone else.Tegucigalpa
A
0

If you are willing to pay for NAT gateway (per hour charge + per GB traffic processed) , you can create a NAT gateway to make Elastic IP attach to your VPC private Subnet(you need to create route for subnet , point to nat-gateway, and modify your default route point to igw-id).

Any EC2 instance restart will have effect on the Elastic IP afterwards.

Authoritarian answered 16/3, 2016 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.