From the course: Hands-On Development in AWS
Understanding elastic IPs - Amazon Web Services (AWS) Tutorial
From the course: Hands-On Development in AWS
Understanding elastic IPs
- Elastic IPs are IP addresses that are publicly routable on the public internet. These are IP addresses that are owned by either Amazon or by you, that you can then assign to an instance. And whenever you assign it to an instance, it will then do the public to private translation through an internet gateway for you, using an IP address that will be retained through stops and starts of an instance. If you are ever going to put an instance into a DNS zone, referencing a name to an IP address, then you are most likely going to want to use an Elastic IP, and I will give you a demonstration of why that is. I have my live demos instance here up and running. We can see it's public IPv4 address of 3.84.188.9. I have logged into this instance right here. If we run a curl http://169 254 169.254/latest/metadata, we can access a private rest API that is accessible per instance. So in here is a local IPv4 endpoint. We can query that, public IPv4, and we'll tack on an echo there and we can see our public IP 3.84.188.9. That IP address matches right here. I'm going to instance state stop, I'm going to stop this instance, it will kick me out, over here, and we will give this a second to fully stop, or a few seconds. Our instance has stopped. So if we were to click on it here, we can see that we have no more public IPv4 address. Now imagine that this instance was in route 53. So the public IP, the previous public IP of 3.84 188.9 was in the public DNS zone record for whatever I was doing, myawesomewebsite.com maps to 3.84.188.9. I just stopped the instance and now I'm going to restart it. Instance state start. And we'll hit the refresh up here, and very soon we should have a public IP address available to us, while it is launching, it will assign a public IP, so 3.95 178.172, we compare that new IP address to what we had before, and we can see they do not match. So 3.95 does not match 3.84, so if you imagine having that IP in a DNS zone record, that's going to be a problem. Anytime the instance is stopped and started, it's possible for you to get a new IP address, that's not helpful for DNS records. So let's head over here to our elastic IPs in EC2 service, and we are going to allocate an elastic IP address. We will use one from Amazon's pool, in US East one and hit allocate. Now when it comes to paying for an elastic IP address, you pay for the IP when you're not using it. So as soon as I select this elastic IP, and do an associate elastic IP address, we're going to choose the instance of live demos and associate. Once I've done that association, I'm not paying for this reservation. You pay for the reservation if you don't use it. When you allocate an elastic IP, it's assigned to you, it is yours to use in perpetuity. However, if you don't associate it with an instance, you're going to pay for it in perpetuity. So don't try to hoard IP addresses. Amazon is not going to let you do that without paying for it. Also, there is a limit on the number of elastic IPs per region. Let's go ahead and allocate a couple more here. Allocate one, unused, let's allocate another one, unused. That's three total, let's get one more. That's four, and we will grab another one. Allocate. So I should have five now. There's my five elastic IPs. Grab another one, hit allocate, and we have an error here, maximum number of addresses has been reached. You can request an increase to this particular limit. It is over here in limits. Limits, in the upper left. We search for elastic IPs, EC2-VPC elastic IPs, current limit is five. Select that, and request limit increase. Then you would submit a support case and explain why you need more. Now this is this free trial account that I created as part of this course and if I submitted this case right now, they would deny it. An account needs to be of a certain age before they will do this increase for you. All right, let's go back. I need to get rid of those elastic IPs because I don't want to pay for them. So let's go back to the EC2 service. And we will go to elastic IPs. I'm in the wrong region, just a moment. And the one that is associated is right there, you can see all these other ones are unused so we can go ahead and select them all minus that one and then release elastic IPs. And these are gone and I'm no longer paying for them. I do still have the one that is associated with this instance. It was 57.137 and we can see that IP listed right here, 57.137, and now this IP address will persist across stops and starts of my instance. Let me go ahead and connect to this. I'm going to go ahead and save this particular IP in the connection profile so that I don't have to update it next time. We'll hit connect, accept the new cert, certs are tied to IP addresses. We are logged in successfully. Let's go ahead and stop the instance. So take a few seconds, and then when it is stopped I will restart it and we should see that that elastic IP is maintained. So we are stopping. Our instance has stopped and I'm going to start it again. And we can see that it already has the IPv4 DNS here because we have that elastic IP assigned, we don't have to wait for it to go grab one and assign it. We have the elastic IP associated. So while this is still pending in instant state, we already know it's public IP address, and this should be launched right about now. Still pending. It is now running and we can connect back to it using that same IP address. So elastic IPs are re-assignable IP addresses. They do persist through stops and starts of an instance. Looks like it wasn't actually up and running yet there. And I've just connected. That same curl, curl http://169 254 169.254/latest/metadata/public-ipv4. So we can see there our, right there. That's why I did that echo in the previous execution. There's our elastic IP. That it is working properly. So this is an IP that we would want to put into a DNS server. So that's the elastic IPs in a nutshell.