How to assign an Elastic IP to your EC2 instance

How to assign an Elastic IP to your EC2 instance

Case Scenario:

I created a python app and hosted it on a AWS EC2 instance. I happily shared the public IP on my LinkedIn page, Twitter Account, Blog and send it to multiple people via direct messages.

Since I was experimenting hosting the app on multiple EC2 instances(Ubuntu, Linux and Windows), I had multiple instances running on my dashboard. So, I decided to clean my workspace and kill a few unused instances. Now if you cannot guess what happened next, I accidentally stopped the instance on which my app was running.

No alt text provided for this image

This was my instance's public IP before stopping. When the instance came back up, the public IP had changed.

No alt text provided for this image

Now in a situation where this happens, you will need to re-share the link of your application with everyone again. There has to be a solution for this. Elastic IP comes to the rescue.

Here is what you can do:

Before you start, you need to know that Elastic IP does not cost you anything if it is attached to a resource. However AWS does charge you $0.01/hr for each EIP that you reserve and do not use. You will understand what attaching to a resource means as your read further.

  • Go to your EC2 dashboard and click on Elastic IPs under Network and Security.
No alt text provided for this image
  • Click on Allocate Elastic IP address
No alt text provided for this image
  • Click on allocate again and you get a new Elastic IP.
No alt text provided for this image

Now that you have created an elastic IP, you need to associate this with your EC2 instance.

  • Go to actions and click associate Elastic IP address.
No alt text provided for this image
  • Select the instance with which you want to associate this Elastic IP and click Associate.
No alt text provided for this image

Now if you go to the instance and check, you can see that the public IP of the instance changes to the Elastic IP.

No alt text provided for this image

Now this public IP won't change even if you stop and start the instance.

Do try it out, and let me know if you have any questions.




To view or add a comment, sign in

More articles by Abhishek Gupta

Insights from the community

Others also viewed

Explore topics