Chapter 14: EC2 Operations — Elastic IP, AMI, Snapshots and Vertical Scaling
14.1 Elastic IP in depth
Quick answer: the short, self-contained version of this lesson is the guide How to Attach an Elastic IP to an EC2 Instance.
Why do we need it?
Remember Chapter 1 and 5: the auto-assigned public IPv4 address is released when you stop the instance, and a new one is given when you start it. Your DNS record, your WordPress site URL, your friends' bookmarks — all point to the old IP and break. Bagha, an Elastic IP (EIP) solves this: it is a static public IPv4 address that belongs to your account (not to an instance) until you release it.
Think of it like a landline number that you keep even when you shift to a new flat — you just "port" it to the new address. Technically, AWS keeps a 1:1 NAT mapping at the Internet Gateway from the EIP to the private IP of the instance (its network interface), and you can change that mapping at any time.
| Point | Auto-assigned public IP | Elastic IP |
|---|---|---|
| Survives stop/start | No — new IP after start | Yes |
| Owned by | The instance (temporarily) | Your AWS account |
| Move to another instance | Not possible | Yes — re-associate in seconds |
| Default limit | — | 5 per region per account (a service quota; you can request more) |
| Charges | Public IPv4 is charged hourly | Public IPv4 is charged hourly — whether attached or idle |
Public IPv4 addresses cost money
AWS charges an hourly fee for every public IPv4 address, including Elastic IPs — attached to a running instance, attached to a stopped instance, or just sitting unassociated in your account. Check the current rate on the Amazon VPC pricing page. Lakshat theva: release EIPs you no longer need.
Allocate and associate (console)
Come on, now let's allocate an Elastic IP for our web server and attach it. Three steps: allocate, associate and verify.
चला, आता आपल्या वेब सर्व्हरसाठी Elastic IP ॲलोकेट करून अटॅच करूया. तीन स्टेप्स: ॲलोकेट, असोसिएट आणि व्हेरिफाय.
चलो, अब हमारे वेब सर्वर के लिए Elastic IP एलोकेट करके अटैच करते हैं. तीन स्टेप्स: एलोकेट, एसोसिएट और वेरिफ़ाई.
Step 1 — Allocate: EC2 → Network & Security → Elastic IPs → Allocate Elastic IP address → Network border group: your region (e.g. ap-south-1) → Public IPv4 address pool: Amazon's pool of IPv4 addresses → add tag Name=web-eip → Allocate.
Step 2 — Associate: select the EIP → Actions → Associate Elastic IP address → Resource type Instance → choose the instance (and its private IP) → Associate.
Step 3 — Verify: the instance's Public IPv4 address now shows the EIP. From the server:
curl -s https://checkip.amazonaws.com # should print the Elastic IP
The old public IP is gone
When you associate an EIP, the instance's previous auto-assigned public IP is released immediately. Reconnect SSH using the new Elastic IP. If you later disassociate the EIP, the instance gets a fresh auto-assigned IP (if its subnet setting allows) — not the old one.
Server replacement with zero DNS change
This is the most useful real-world trick with Elastic IPs. Suppose web-1 is old and you have built a new, upgraded web-2:
Before: www.example.com ──► EIP 13.232.50.10 ──► web-1 (old)
After: www.example.com ──► EIP 13.232.50.10 ──► web-2 (new) DNS record unchanged!
- Build and test
web-2using its own temporary public IP (or an AMI ofweb-1, see 14.2). - Select the EIP → Actions → Associate Elastic IP address → choose
web-2→ tick Allow this Elastic IP address to be reassociated → Associate. - Traffic now goes to
web-2within seconds. Keepweb-1stopped for a day as a rollback option, then terminate it.
Disassociate and release
- Disassociate: select the EIP → Actions → Disassociate Elastic IP address. The EIP stays in your account (still charged).
- Release: select the EIP → Actions → Release Elastic IP addresses → Release. The address goes back to AWS. You can often recover it soon after with
aws ec2 allocate-address --domain vpc --address <the-ip>if it is still free and within your quota; otherwise you get a new IP.
AWS CLI equivalents (optional)
aws ec2 allocate-address --domain vpc
aws ec2 associate-address --instance-id i-0123456789abcdef0 --allocation-id eipalloc-0abc1234def567890
aws ec2 associate-address --instance-id i-0fedcba9876543210 --allocation-id eipalloc-0abc1234def567890 --allow-reassociation
aws ec2 describe-addresses --output table
aws ec2 disassociate-address --association-id eipassoc-0123abcd4567ef890
aws ec2 release-address --allocation-id eipalloc-0abc1234def567890
Ravindra Bagale's Tip
Attach the Elastic IP before you create DNS records (Chapter 9), install WordPress or configure server_name – then nothing ever needs to change. And when you finish a lab, do a quick "EIP audit": EC2 → Elastic IPs – release every EIP without an associated instance. That's all, and your bill stays clean.
Ravindra Bagale's Tip – मराठी
Elastic IP DNS records (Chapter 9), WordPress install किंवा server_name config करण्याआधी आधी attach करा – मग काहीच बदलावं लागत नाही. आणि lab संपला की एक छोटा "EIP audit" करा: EC2 → Elastic IPs – associated instance नसलेली प्रत्येक EIP release करा. बस एवढंच, आणि तुमचं bill स्वच्छ राहतं.
Ravindra Bagale's Tip – हिंदी
Elastic IP को DNS records (Chapter 9), WordPress install या server_name config करने से पहले attach करो – फिर कुछ भी बदलना नहीं पड़ता. और lab खत्म हो तो एक छोटा "EIP audit" करो: EC2 → Elastic IPs – बिना associated instance वाली हर EIP release करो. बस इतना ही, और आपका bill साफ़ रहता है.
Lab
Chala, web-eip naavachi Elastic IP allocate karun tumchya web server la associate kara aani curl -s https://checkip.amazonaws.com ne ti disate ka te bagha. Mag instance stop-start kara, IP tasach rahila ka te confirm kara, aani lab sampla ki EIP disassociate karun release kara.
Got it? An Elastic IP belongs to the account, not the instance – so even if you change the server, the address stays the same. Now let's move on to AMIs – a photocopy of the server.
समजलं का? Elastic IP अकाउंटची आहे, इन्स्टन्सची नाही – म्हणून सर्व्हर बदलला तरी पत्ता तसाच राहतो. आता पुढे जाऊया AMI कडे – सर्व्हरची फोटोकॉपी.
समझ आया? Elastic IP अकाउंट की होती है, इंस्टेंस की नहीं – इसलिए सर्वर बदलो तब भी पता वही रहता है. अब आगे चलते हैं AMI की तरफ़ – सर्वर की फ़ोटोकॉपी.