Posted on Leave a comment

Associate Public IP with an EC2 Instance

Here’s how to associate an Elastic IP address with an EC2 instance using AWS CLI:

Step 1: Allocate an Elastic IP address

First, allocate an Elastic IP address using the allocate-address command:

aws ec2 allocate-address --region <region>

Replace <region> with the region where you want to allocate the Elastic IP address. This command will allocate a new Elastic IP address and return the IP address in JSON format.

Step 2: Associate the Elastic IP address with your instance

Next, associate the Elastic IP address with your EC2 instance using the associate-address command:

aws ec2 associate-address --instance-id <instance-id> --public-ip <public-ip> --region <region>

Replace <instance-id> with the ID of the EC2 instance that you want to associate the Elastic IP address with, <public-ip> with the Elastic IP address that you allocated in Step 1, and <region> with the region where your EC2 instance is located.

This command will associate the Elastic IP address with your EC2 instance, making it reachable from the internet.

Step 3: Verify the association

You can verify that the Elastic IP address is associated with your EC2 instance by using the describe-instances command:

aws ec2 describe-instances --instance-ids <instance-id> --query 'Reservations[].Instances[].PublicIpAddress' --output text --region <region>

Replace <instance-id> with the ID of the EC2 instance that you associated the Elastic IP address with, and <region> with the region where your EC2 instance is located. This command will output the public IP address of your EC2 instance, which should match the Elastic IP address that you associated with it.

By associating an Elastic IP address with your EC2 instance using AWS CLI, you can add a public facing network to your instance and make it reachable from the internet.

Leave a Reply

Your email address will not be published. Required fields are marked *