Hello All, It’s been great talking and sharing with you guys. Thank you all for taking out time and reading it, I can only hope that my posts doing what they are supposed to do, simplifying complex technology in simple terms so that every one of you can understand and learn from it. I’m always open to suggestions, you can contact me anytime and I promise to get back to you as soon as possible. Okay, so back to the topic for the day. Well couple of weeks earlier I shared a couple of blog post regarding AWS, What is AWS & Getting Started with AWS. I assume that you have gone through those post and have at least a basic understanding over the concept. Today we are going to dig deep into one of the services provided by AWS i.e. EC2. We covered the basics of EC2 in my previous post. Today we will go through the advance configuration of server in EC2. This is going to be little more complex but I’ll try to simplify as much as possible.
We will start with something simpler — Elastic IP
Before I get into what it is, let’s do a small experiment. I’ve already deployed an Amazon Linux server. Note the Public IP or Public DNS for the server.
Now lets shutdown this server wait for some time and then power back on and observe the behavior of instance. Select the instance, go to Actions > Instance State > Stop. Click on “Yes, Stop” to confirm & initiate the shutdown action.
Wait for sometime. Select the instance, go to Actions > Instance State > Start. Click on “Yes, Start” to confirm & initiate the power on action. It generally takes 2 – 5 minutes to boot up, depending on the instance type.
Now note the Public IP or Public DNS for the server.
Yes, It’s different, It will be different every time you boot up the instance. The question is why? Well it’s quite simple actually. AWS uses DHCP (Dynamic Host Configuration Protocol) to assign the IP address to instances. When you select “Auto Assign IP Address”, during deploying instances, DHCP takes one IP address randomly from the available IP address pool and assign it to the instance & when you shut down the instance, the IP assigned to it goes back to the pool and when the instance is booted up, DHCP assigns new IP address from the pool, this new IP address will be different from earlier IP address.
This behavior can cause a lot of problems, especially while hosting some application or database, since there is no way to predict what IP is going to be assigned, but there is a solution to the issue i.e. Elastic IP. Elastic IP is a way to rent one or more IP addresses, and use them as per our convenience. Once the Elastic IP is assigned to server, it will stay that way until we detached it our self. But there is a catch, AWS will charge you for every hour the Elastic IP is not used. Yes, If the Server has Elastic IP and is up & running, then there is no charge for that particular session. But if the Server is assigned an Elastic IP & server is not running/powered off or simply Elastic IP is reserved and not in used, AWS will charge for every hour Elastic IP is not in used. Also, if you associate more than one Elastic IP with the instance, you will be charged for each additional Elastic IP associated with that instance per hour on a pro rata basis. Additional Elastic IP are only available in Amazon VPC. The charges per hour for Elastic IP is relatively less and if differs from region to region. To check pricing for each region click here.
So let’s see Elastic IP’s in action. Login into AWS console, from service menu select EC2. On left Pane, under “Network & Security”, select “Elastic IPs” to open Elastic IP console.
Click on “Allocate new address”.
Click on “Allocate”, to confirm and assign new Public IP.
Click on Close to continue. Now in Elastic IP’s Dashboard, there is new IP allocated to it. We can use this IP to assign this IP to any server, and we cannot assign one Elastic IP to multiple servers at same time.
So let’s assign our newly allocated IP address to a server. For Implementation purpose, I’ve already deployed a server and have not assigned any public IP to it. It’s very simple, Disable the Auto Assign Public IP in Step 3: Configure Instance Details while deploying an instance. This step is not necessary and Elastic IP will work even if the instance is currently assigned a Public IP. The Elastic IP will simply override the currently allocated Public IP.
Now from Elastic IP’s dashboard, select the Elastic IP that was just allocated. Go to actions and select “Associate Address”.
Select Instance as Resource Type. Choose the Instance from the drop down menu. Select the Private IP from the list and finally Check “Allow Elastic IP to be re associated if already attached” and click on Associate to attach the Elastic IP to the instance.
Elastic IP is now associated with the Instance and Elastic IP dashboard is also updated respectively. Now let’s check the EC2 dashboard, and verify whether the Elastic IP is assigned to the instance or not.
The Elastic IP is now assigned and ready for use. It’s very simple to use it and this IP will stay with us until we release it from Elastic IP dashboard. Select the Elastic IP to release, go to actions. Select “Disassociate Address”. On confirmation window, click on “Disassociate Address” to confirm.
The Elastic IP is now free and can be released or assign to some other server instance, for now let’s release the IP. Select the IP, go to action and choose “Release Address”. On next confirmation screen click on “Release Address”, and now the IP address is back in pool.
Well that’s all for now, as title suggests there will be a Part-2 of this EC2 walk-through, that will be release very soon (Update Deep Dive for EC2 have been released. Click here to visit). In 2nd Installation we will talk about Load balancers, Launch Configuration and Auto Scaling Group. It is one of the best features provided by EC2 as a service. Until then keep learning, take care, see you all soon.