What is an Elastic IP (EIP)?
An Elastic IP address is a static, public IPv4 address provided by AWS that can be assigned to resources within your VPC. Unlike a regular public IP, which may change when a resource is stopped and restarted, an Elastic IP remains constant, making it ideal for situations where a fixed public IP is required.
Role of Elastic IP in a VPC
1. Static Public IP Address for EC2 Instances
Problem with Default Public IP:
- When you launch an EC2 instance in a public subnet, AWS assigns a public IP by default. However, this public IP changes if the instance is stopped and restarted.
Solution with Elastic IP:
- By associating an Elastic IP with your EC2 instance, you ensure that the public IP remains fixed, making it suitable for hosting applications or services accessible via a consistent address.
2. Outbound Internet Access from Private Subnets
Instances in private subnets do not have direct internet access. A common approach to enable outbound internet access for private subnet instances is to use a NAT Gateway.
Elastic IP is assigned to the NAT Gateway, allowing it to route internet traffic on behalf of private instances. Without an EIP, the NAT Gateway cannot communicate with the internet.
3. Recoverability and High Availability
- If an EC2 instance or resource associated with an Elastic IP fails, you can quickly remap the Elastic IP to another instance. This ensures minimal downtime and service continuity.
4. Public Services or APIs
Elastic IPs are useful for hosting web applications, APIs, or services where a static public IP is required. For example:
DNS records can point to an Elastic IP.
Applications requiring IP whitelisting benefit from the fixed address.
Scenarios Where Elastic IPs Are Useful in a VPC
Scenario 1: Public-Facing Application
You launch an EC2 instance in a public subnet to host a website.
By associating an Elastic IP, you ensure that the website's IP remains fixed, even if the instance restarts.
Scenario 2: Internet Access for Private Instances
You create a VPC with public and private subnets.
Instances in the private subnet need internet access for updates or external API calls.
You create a NAT Gateway in the public subnet, assign an Elastic IP to the NAT Gateway, and configure the route table of the private subnet to use the NAT Gateway for internet-bound traffic.
Scenario 3: Failover and Recovery
A critical application runs on an EC2 instance.
In case of instance failure, you can quickly launch a replacement instance and reassign the Elastic IP to it, ensuring uninterrupted access.
Advantages of Elastic IPs
Consistency: A fixed IP ensures stability for DNS records, IP whitelisting, or external API integrations.
Flexibility: You can reassign Elastic IPs to different resources as needed.
Scalability: Elastic IPs support dynamic scaling and recovery scenarios.
Internet Access: Enables private subnet instances to access the internet via NAT Gateways.
Disadvantages or Considerations
Limited Quota: AWS limits the number of Elastic IPs per region (default is 5). Additional EIPs require a request for quota increase.
Cost: AWS charges for unused Elastic IPs, so it's important to disassociate and release them if not needed.
IPv4 Limitation: Elastic IPs only support IPv4. For IPv6, AWS uses different mechanisms (e.g., Egress-only Internet Gateways).
"Thank you for reading! I hope this blog sparked new ideas and insights. If you have questions or thoughts, drop a comment below. Until next time, keep learning and growing!"
Reach out to me at linkedin.com/in/sruthipalle
Happy Coding😊