Amazon EC2 instance and Elastic IP address - amazon-web-services

Currently I have a running EC2 instance and one Elastic IP address allocated to it. Now I want to create a new instance for a demo project that will be using Elastic Beanstalk.
Question:
If I create one more new Elastic IP address for the newly created instance, will there be a charge to it?
If there is a charge, can I use the same elastic ip address for the newly created instance while running the current instance? If possible will there be a charge to it?

You will be charged for the new elastic IP until the IP is attached to a running instance - approximately $0.005/hour
Since the elastic IP is unattached between the time it was allocated and it was attached to a running instance, you'll be charged for at least one hour which is half a cent - $0.005/hour
From Elastic IP Charges
An Elastic IP address doesn’t incur charges as long as the following conditions are true:
The Elastic IP address is associated with an Amazon EC2 instance.
The instance associated with the Elastic IP address is running.
The instance has only one Elastic IP address attached to it.

Related

Allocating an Elastic IP address to an existing / running Amazon EC2 instance

Are we able to allocate an Elastic IP address to an existing / running Amazon EC2 instance?
In most cases, we assign the Elastic IP address before configuring the server. However, we are trying to assign the Elastic IP address onto a fully configured server and create an AMI for different instances.
If we associate the new EIP onto an existing instance (created by AMI) will run the same config as the existing one?
Elastic IPs can be allocated and associated to an EC2 instance at any time, while launching or after the launch.
An Elastic IP address is not actually the property of your instance, rather it's a property associated with your server's network card (Elastic Network Interface).
See: Elastic IP Addresses - Amazon Virtual Private Cloud

Why IP address changed whenever we start or stop the Ec2 service?

whenever i tried to start or stop the Elastic compute cloud the IP address will be change.
Elastic IP is free as long as it is associated with an instance.
When you create your instance, you can choose to create a new Elastic IP and associate it with the instance. If you did not do this, you will be using the public pool of IP addresses Amazon provides that is available to EC2 instances.
IP from such public pool cannot be converted into Elastic IP. In your case, you need to simply create a new Elastic IP, then associate it with your instance.
An Elastic IP address doesn’t incur charges as long as the following
conditions are true:
The Elastic IP address is associated with an EC2 instance.
The instance associated with the Elastic IP address is running.
The instance has only one Elastic IP address attached to it.
For pricing please see AWS Documentation.

How long is an Elastic IP valid in AWS? Is it terminated after sometime?

How long is an Elastic IP valid in AWS? Is it terminated after sometime ?
I requested an elastic IP from AWS EC2 console and got one. How long can i use the elastic IP.? Will AWS take it back after sometime or will remain with me as long i have an AWS accoutn
Elastic IP allocated to an account. You can associate/reassociate to any instance or you can leave the elastic IP without associating it to any instance. The elastic IP is assigned to the account until you release it.
For more information: Elastic IP Addresses
You won't be charged as long as the elastc ip is associated with a running instance. Else you will be charged a small fee ($0.005/hour)
Elastic Ip is valid till you don't release them manually from your account.
You will be charged for elastic IP if it is not associated with any instance. For more details visit http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html

Possible to associate Elastic IP to an instance without immediately losing public ip?

I have a windows EC2 instance running a production website and DNS is configured to have my domain name point to its public IP. There is currently no Elastic IP (EIP) associated with the instance. I would like to start using a Elastic IP and have my domain name point to it instead of the public IP (which can change if I ever have to change the instance).
Reading the documentation I find this statement troubling:
When you associate an EIP with an instance, the instance's current
public IP address is released to the EC2-Classic public IP address
pool.
My fear is this:
I assign an EIP to the instance and the public IP is released.
Now my website no longer works, because the domain name points to the public IP, which is no longer associated with my EC2 instance.
I must then point DNS records to the EIP. But this could take up to 48 hours for propagation to take place (i.e. my site may be be unreachable for up to 48 hours).
How can I do this without having to live through DNS propagation?
If your EC2 instance is in a VPC, you can add a second network interface onto your EC2 instance. You can associate your Elastic IP address with that second network interface. This way, your EC2 instance could respond to both IP addresses.
Instructions
Create a new Network Interface in the same subnet as your EC2 instance.
Allocate a new Elastic IP for your VPC (if you haven't done so already).
Associate the Elastic IP address with your new Network Interface (eni).
Attach your new Network Interface to your EC2 instance.
Do not change your DNS yet.
You may need to RDP/SSH into your EC2 instance to make some configuration changes to ensure your EC2 instance responds correctly to the new IP address.
Modify the hosts file on your local computer to test connecting to your website via the new IP address.
When that works, do the DNS switch and restore your hosts file.
48 to 72 hours before your pre-determined switch-over time, reduce the time-to-live (TTL) on your DNS entry to 300 seconds (5 minutes).
At your designated switch-over time:
Attach the Elastic IP address
Update your DNS entry to point to your Elastic IP address
Doing this, your effective "downtime" is reduced to 5 minutes.
You can have two identical EC2 instances. One with the old public IP where DNS record is pointing to. One with the EIP assigned. Requests should be able to access anyone of the two instances without noticing it. Your application must be able to scale horizontally. Then you change DNS record to point to EIP. Eventually, when DNS is updated, all requests to your domain will end up going to the EC2 instance with the EIP. At that moment you can stop or terminate the old EC2 instance.
Other possibility if your application cannot scale horizontally and if it is a web application, the web server in the old EC2 instance can redirect requests to the EIP. It would redirect to an IP address but it's a possibility.
If you don't use EC2-Classic instances, you can freely move the Elastic IP to any other EC2 instance without losing the EIP.
aws ec2 associate-address --region us-east-1 --allocation-id eipalloc-xxxxxxxxxxx --allow-reassociation --network-interface-id eni-xxxxxxxxxx
where eipalloc-xxxxxxxxxxx is the id of the Elastic IP and eni-xxxxx is the id of the target EC2 instance.
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-recover-ip-address/
Elastic IP addresses
It's a best practice to use an Elastic IP address. Elastic IP addresses are allocated to your account, instead of to the instance. You can associate your Elastic IP addresses to and from instances as needed.
If you release the Elastic IP address that was allocated to your account, you might be able to recover it. For more information, see Recovering an Elastic IP address.
All instances except EC2-Classic instances retain their associated Elastic IP addresses when stopped. AWS continues to bill for Elastic IP addresses associated with a stopped instance.
Note: Elastic IP addresses associated with EC2-Classic instances aren't recoverable.

Elastic IP needed to be "re-associated" after stop/start

I had an issues with my AWS EC2 instance today. It was hanging with cpu at 100%...not sure why, but that's for another post.
I stopped the instance, and restarted it. After that, I couldn't get to my website. The Public DNS changed (I think this is normal as amazon may have moved me to another machine). I then looked at Elastic IP, and the entry is still there, but in the 'Instance' column, it was blank. I had to click 'Associate Address' and set the instance.
Is this normal? I was under the impression that Elastic IP should not need to be touched even after a stop/start. Did something go wrong? Is there something I can to find out why this happened?
Is the instance in EC2 classic or EC2 VPC?
The elastic IP is disassociated when you stop the instance in EC2-Classic, but is retained in EC2-VPC. So I assume your instance is in EC2-Classic, where the elastic IP is disassociated when the instance is stopped. You need to re-associate when you start the instance.
For more info
EC2-Classic: We disassociate any Elastic IP address (EIP) that's
associated with the instance. You're charged for Elastic IP addresses
that aren't associated with an instance. When you restart the
instance, you must associate the Elastic IP address with the instance;
we don't do this automatically.
EC2-VPC: The instance retains its associated Elastic IP addresses
(EIP). You're charged for any Elastic IP addresses associated with a
stopped instance.