How to Associate Elastic IP in EC2 Instance in AWS?

Description of the image

In this rapidly growing world of cloud computing, it's crucial to maintain a consistent and dependable connection to your resources. Amazon Web Services (AWS) provides a dynamic solution for Elastic IPs and static public IP addresses for your EC2 instances. Earlier, associating an Elastic IP needed a separate allocation and association procedure. 

However, now, AWS has launched a new feature where you can simply associate Elastic IPs directly during the EC2 instance launch. With this, you can easily configure an Elastic IP to be instantly associated with your EC2 instance at creation time.

Understanding Elastic IPs: A Public IP Address on Demand

By default, the EC2 instance is allocated a private IP address within your Virtual Private Cloud (VPC) or the conventional EC2 network. While this enables internal communication within your AWS infrastructure, it blocks external access from the internet. Let's understand where Elastic IPs step in.

Elastic IP is like enhanced public IP addresses. You can easily assign static IP addresses to your EC2 instance, providing a reliable and consistent entry gate for inbound connections. This certainly proves invaluable in scenarios like:

  • Web servers: They enable you to grant public access to your website or application hosted on an EC2 instance.
  • Remote desktop access: With Elastic IPs, you get secure remote connections to your EC2 instance for administrative purposes.
  • Game servers: They offer a reliable and consistent public IP address for players to link to your game server.

Elastic IPs offer a plethora of benefits over conventional public IP addresses allocated by your ISP:

  • Flexibility: You can associate and disassociate Elastic IPs from EC2 instances effortlessly, providing full and dynamic control over public accessibility.
  • Durability: Elastic IPs are different from public IP addresses that can change with reboots. However, Elastic IPs are much more persistent and stay available even after instance termination.
  • Cost-effectiveness: You have to pay for the time an Elastic IP is allocated and not for the complete billing cycle.

Prerequisites for Association: Gearing Up for Success

Before heading towards the association journey, make sure that you hold the following with you:

  • An AWS Account: First, Sign up for a free tier account if you're new to AWS
  • An EC2 Instance: Then, take another step by launching an EC2 instance in the region of your choice. However, ensure it's running well in a public subnet with internet gateway access for external communication.
  • Security Groups: To permit inbound traffic on the ports you use regularly, like port 80 for web traffic or port 22 for SSH access, you need to configure security groups.

Pro Tip: When launching your EC2 instance, you can pick the option to "Assign a public IP address" during configuration. This way, the allocation of Elastic IP to your instance automatically gets done. Yet, for other granular control and cost optimization, the manual association process is considered.

Step-by-Step Guide For Association Process

Now, let's see the association process by navigating via the AWS management console:

  1. Access the EC2 Console: Firstly, log in to the AWS Management Console and then navigate to the EC2 service. 

    navigate to the EC2 serviceStep-3.png
  2. Navigate to Elastic IPs: Locate the "Elastic IPs" section in the navigation pane.

    Locate the "Elastic IPs
  3. Allocate a New Address: Now click on the option "Allocate Elastic IP address".

    click on allocate button
  4. Choose Allocation Method: You need to choose either "EC2-Classic" or "VPC" based on where your EC2 instance is actually residing. In the case of most modern deployments, VPCs are required.
  5. Allocate the Address: Click on the button "Allocate" to confirm the allocation further. Then, you'll see a newly formed Elastic IP with a public IP address assigned to it.

Voila, you've successfully allocated an Elastic IP. Now, you need to associate it with your EC2 instance. Let's dive in.

  1. Locate the Elastic IP: Check the list of Elastic IPs and then recognize the one you have just allocated. 
  2. Associate the Address: Then, right-click on the Elastic IP and choose the option "Associate Address".
  3. Choose the Target Instance: You'll see a pop-up window where you need to choose the EC2 instance you desire to associate the Elastic IP with from the "Instance ID" dropdown menu.

    choose running instance
  4. Specify the Private IP: You can pick the particular private IP address within your instance to associate the Elastic IP with, which is optional. It will associate with the primary private IP by default.
  5. Associate and Verify: Now click on the button "Associate" to finalize the association. After this, you'll receive a confirmation message, and the associated instance ID will be reflected further to the Elastic IP in the list.

Double-check: Go back to the EC2 instances in the console region. Then, choose your instance and find the "Public IPv4 DNS" field. Now, you will see the public IP address of your associated Elastic IP, which verifies your successful configuration.

Note: You can also go through the below video

Association Process by CLI

Step 1: Allocate an Elastic IP Address

aws ec2 allocate-address --domain vpc

Step 2: Associate the Elastic IP Address with the EC2 Instance

aws ec2 associate-address --instance-id i-1234567890abcdef0 --allocation-id eipalloc-12345678

Step 3: Checking the Association

aws ec2 describe-instances --instance-id i-0abcdef1234567890

Advanced Techniques and Best Practices for Elastic IP:

  1. Disassociation and Release: Manage the disassociation properly and release by navigating further to the Elastic IPs section in the EC2 console. You can disassociate an Elastic IP to block the connection between the Elastic IP and the EC2 instance and release it if there's no further requirement.
  2. Automating Associations: Facilitate the procedure of associating Elastic IPs for huge-scale deployments with the help of automation tools like AWS CLI and SDKs for different programming languages.
  3. Optimizing Billing: Check properly Elastic IP usage to find out and release any unused IPs. Then, try using Schedules Instances or Spot Instances for cost savings, and make sure you pay only for the IPs active currently.
  4. Security Considerations: Apply top-notch security practices like configuring security groups to permit inbound traffic only on important ports, using IAM roles for access control, and checking EC2 instances for any suspicious activity to improve security.


Elastic IPs certify you to develop consistent and dependable connections to your EC2 instances in the AWS cloud. When you understand the allocation, association, and management processes, you can use the flexibility and cost-effectiveness of Elastic IPs. 

Just keep in mind that you should implement automation for efficiency, optimize billing to control costs, and prioritize security to protect your resources. With all these practices in place, you'll be well on your journey to achieving consistency in connection and maximizing the value of your Elastic IPs in your AWS deployments.

Read More

Follow us on

Table of Contents

    Subscribe to Us

    Always Get Notified