Laptop Marts is pleased to announce that we now provide the IT & Pro-AV products to Corporates as well.

How to Create an EC2 Instance and Attach an Elastic IP Address: A Step-by-Step Guide

Introduction:

Amazon EC2 (Elastic Compute Cloud) provides scalable computing capacity in the AWS cloud, making it a powerful tool for hosting applications, websites, and more. To ensure that your EC2 instance maintains a static, public IP address even when restarted, you can assign an Elastic IP. In this guide, we’ll walk you through the process of creating an EC2 instance and attaching an Elastic IP to it.

What You’ll Learn:

  • How to launch an EC2 instance on AWS
  • What an Elastic IP is and why it's useful
  • Step-by-step instructions to attach an Elastic IP to an EC2 instance
  • Common use cases for Elastic IPs in cloud infrastructure

Step 1: Log in to the AWS Management Console

First, log in to your AWS account and navigate to the EC2 Dashboard from the AWS Management Console.


Step 2: Launch a New EC2 Instance

  1. In the EC2 Dashboard, click Launch Instance.
  2. Choose an Amazon Machine Image (AMI) – for this example, you can select Amazon Linux 2 AMI (HVM).
  3. Select an Instance Type. For most use cases, a t2.micro instance (which falls under the free tier) is sufficient.
  4. Configure your instance settings, such as network and storage. By default, it will be launched in a VPC (Virtual Private Cloud).

Step 3: Configure Security Groups

AWS security groups act as virtual firewalls. To allow traffic to your instance:

  • Create a security group or use an existing one.
  • Ensure port 22 is open for SSH access, and port 80 or 443 is open for HTTP/HTTPS traffic, depending on your use case.

Step 4: Launch the EC2 Instance

After reviewing your settings, click Launch. You will be prompted to create or use an existing key pair for secure SSH access. Download this key and keep it safe.


Step 5: Allocate an Elastic IP

Now that your EC2 instance is running, it's time to assign an Elastic IP:

  1. Go to the Elastic IPs section under the EC2 Dashboard.
  2. Click Allocate Elastic IP Address.
  3. You can either allocate a new IP from Amazon’s pool or use one you already have (if applicable).
  4. After the IP is allocated, click Actions and select Associate Elastic IP Address.

Step 6: Associate the Elastic IP with Your EC2 Instance

  1. In the association settings, choose your running EC2 instance.
  2. Select the instance's private IP address.
  3. Click Associate to link the Elastic IP to the instance.

At this point, your EC2 instance will have a static, public IP address that will remain unchanged, even if the instance is restarted.


Step 7: Access Your EC2 Instance

Now that your instance has an Elastic IP, you can access it via SSH. Use the following command from your terminal (make sure you have the private key from Step 4):

ssh -i "your-key.pem" ec2-user@your-elastic-ip

Replace your-key.pem with the name of your private key file and your-elastic-ip with the actual Elastic IP assigned to your instance.


Conclusion:

By following these steps, you've successfully created an EC2 instance and assigned it a static Elastic IP. This process ensures that your instance is reachable at a consistent public IP address, making it ideal for hosting websites, applications, or other cloud-based services. AWS EC2 combined with Elastic IPs offers flexibility, scalability, and control over your cloud infrastructure, helping you deliver reliable services without the worry of IP address changes.


FAQs:

Q1. What happens if I stop my EC2 instance?
Stopping an EC2 instance doesn’t affect the Elastic IP. Your Elastic IP will remain associated with the instance until you manually disassociate it.

Q2. Are Elastic IPs free to use?
Elastic IPs are free as long as they are associated with a running instance. AWS charges you for unused Elastic IPs, so be sure to release them if not needed.

Q3. Can I assign multiple Elastic IPs to one EC2 instance?
Yes, you can assign multiple Elastic IPs to an instance, but this may depend on the type of instance and your AWS VPC settings.


Call-to-Action:

Ready to get started with AWS EC2? Follow this step-by-step guide to create your own instance and attach an Elastic IP to ensure a stable and reliable cloud infrastructure for your business needs

You May Also Like

Can we help