Why you may need a static IP address for EC2 instance

This article explains how to add an Elastic IP to your AWS EC2 instance and why this is so important.

If you are looking a tutorial for AWS check out these:

In this post:

What is elastic ip in AWS

In AWS (Amazon Web Services), an Elastic IP (EIP) is a static public IPv4 address that you can allocate to your AWS resources, such as Amazon EC2 instances, NAT gateways, and some load balancers. The term "elastic" refers to the fact that you can easily associate and disassociate the IP address with your instances and other resources, making it flexible and portable.

When you launch a new EC2 instance in AWS, it is assigned a dynamic public IP address by default. However, this dynamic IP address can change whenever you stop and start the instance, or if there's any interruption in the underlying infrastructure.

On the other hand, an Elastic IP address remains associated with your AWS account until you explicitly release it. This makes it useful for scenarios where you need a consistent, public IP address for your resources, such as hosting a website, setting up a VPN, or accessing resources from the internet.

By using an Elastic IP, you can:

  1. Associate a persistent public IP address with your instance or other resources, ensuring that the address remains the same even after instance stop/start cycles.
  2. Reserve an IP address in your AWS account, which can be useful for scenarios where you want to ensure that the IP address remains unchanged even if the instance is terminated and later relaunched.
  3. Easily remap the Elastic IP to different instances or resources within the same AWS account, providing a level of flexibility for your architecture.
  4. Also you might want server's IP address static if it calls 3rd party APIs and you need to whitelist its IP address. Elastic IP address will be used when server is making outgoing connections.

Requirements

In order to be able to do what is described in the article you should have all of the following: - Create an account in https://app.appliku.com/ - Make sure you have credentials set for AWS

How to add Elastic IP Address to the instance

First create an EC2 instance through Appliku dashboard.

Select a region and an EC2 instance type and click "Create EC2 Instance" button. image

You will be redirected to the server page.

Wait until server is provisioned and server setup is complete. Refresh the page if you don't see any changes. If "Server Setup" says "Error" check the tab Setup Logs and try to create another instance. image

Click on the link "Manage Server in AWS Panel"

You will see the page with your instance. Tap on the Name column of the instance to select it and observe the current public IPv4 address of the server.

In the left sidebar find and click on "Network & Security -> Elastic IPs". image

How to create elastic ip in AWS

On the "Elastic IP Addresses" page click "Allocate Elastic IP Address" button. image

On the "Allocate Elastic IP Address" page make sure Amazon's pool of IPv4 addresses radio button is selected, region is the same as your server and click "Allocate" button. image

You will be taken to the list of Elastic IP addresses.

Make sure the address you have just created is selected and from "Actions" menu click "Associate Elastic IP Address".

Associate elastic ip with ec2 instance

image

You will be taken to the page "Associate Elastic IP address".

Make sure that "Resource type" is set to instance. From the instance dropdown select the instance we created through Appliku dashboard and click "Associate" button.

image

You will be taken bacl to list of Elastic IP addresses.

You can see now that IP is associated with the instance we selected.

image

Go back to Appliku dashboard with the details of the server. Refresh it and you will see that server's ip address is now same as the elastic IP address. image

Go to the "Run a command" tab and run the following command:

curl 'https://api.ipify.org?format=json'

image

You will see that the returned IP is our new Elastic IP, which means it is used for outgoing connections.