Start an aws ec2 machine with elastic IP - amazon-web-services

In aws ec2 machines,is there a way to start up an instance and tell it to use an Elastic IP?
Perhaps using user data or something?
Assigning IP to an aws ec2 machine after launch is pretty simple,following the amazon docs,but I would like to launch a machine with the elastic ip.
i.e) While the machine is launches itself, it should be assigned with the IP.
Someone has asked this in the aws support forum 10 years ago, the thread has no solution though.
https://forums.aws.amazon.com/thread.jspa?threadID=20927

It appears that this can be done:
Create a Network Interface
Attach the Elastic IP to the Network Interface
When launching the Amazon EC2 instance, specify the Network Interface to use (that is, the one created earlier)
The instance will then be launched with the Elastic IP address.
There does not appear to be a way to do this totally within the RunInstances command. Only a PublicIP address can be requested, which is temporary and is not an Elastic IP address.

Related

Odoo on aws and docker containers

I am running odoo on an ec2 instance -aws.
The odoo code is pulled from the docker hub, running inside the ec2 via docker containers.
The problem is that the ec2 doesn't have a static IP and every time it's restarted the connection with odoo disappears.
This is at least the theory am working with.
I would appreciate other solutions or might be problems
You need to associate an Elastic IP to your ec2 instance. This will give your ec2 a fixed public IP address
You can follow the documentation in AWS below:
Associate an Elastic IP address with an instance or network interface.
Take in account that there are costs associated: pricing

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

Assign a static IP in AWS

We all know that we can assign a Elastic IP associated with EC2 instance. However, when we rebuild the environment in ElasticBeanstalk the IP still changes since the old instance is terminated and a new instance is created. Is there any way we can assign a "real" static IP so that it wouldn't change even if it's rebuilt in ElasticBeanstalk? Thanks in advance.
From Using Elastic Beanstalk with Amazon VPC:
For single-instance environments, Elastic Beanstalk assigns an Elastic IP address (a static, public IP address) to the instance so that it can communicate directly with the Internet.)
For Load-balancing, autoscaling environments, you should always communicate via the Elastic Load Balancer, which is referenced by DNS Name.
If you require a fixed IP address for whitelisting, there are a few choices:
Route outbound traffic to the remote service via a NAT Gateway -- it can use a fixed Elastic IP address
Route traffic via a proxy in your VPC -- again, it can use a fixed Elastic IP address
Given that you have an auto-scaled environment, it doesn't necessarily make sense to allocate IP addresses to each individual instance. However, if you know the maximum number of instances that will be created, you could create Elastic IP addresses for your EC2 instances and re-associate them to instances when they are re-created. (You could potentially do this via a startup script.)
I agree with John. But just in case if you any way need EIP ( probably to ssh to the server ) : One workaround is Go to EC2 --> Elastic IPs --> Allocate new address . This way you are buying a fixed EIP for your account. Now you can manually associate this EIP with any of your EC2 instance.
Problem with this approach is that you have to always MANUALLY associate EIP.

Changing IP address for Cloudera in EC2 EBS instance

I have cloudera installed in one m1.large instance .
I was able install it successfully.
But once i stop the instance and start it again next morning the IP changes and cloudera still refers to old IP and none of the services run .
How can i solve this problem because i can not keep instance up whole day?
Since its for academic purpose and I don't have a budget .
This doesn't really have anything to do with Cloudera -- more the behavior of EC2 Instances. The feature you're looking for is called an Elastic IP Address, which is a static IP address that you can assign to your EC2 instance. Elastic IP behavior has some differences in EC2-Classic and EC2-VPC, noted here. Most notably for you will be instance startup behavior regarding Elastic IP addresses, which I'll get to shortly.
You can find details on Elastic IP pricing here. Note that while your first Elastic IP address (associated with a running instance is free), you will be charged by the hour for the time that your instance is offline and you still have the Elastic IP Address. This rate is "$0.005 per Elastic IP address not associated with a running instance per hour on a pro rata basis." So not very expensive, but there is some expense to be aware of.
Another recent question has a couple of good answers on how to allocate the Elastic IP address on instance startup. In EC2-Classic you will need to script it or do it manually. In VPC the Elastic IP will remain associated with the instance. (I think you're still charged the fee, though, per this documentation claiming that a small hourly fee is charged if an Elastic IP is associated with a stopped instance.)
If any expensive is prohibitive, I would recommend looking into AWS Command Line Interface to get the new public IP of the EC2 instance on startup and writing a script to change that IP address in your configuration.
You can setup your machine inside a VPC:
By launching your instances into a VPC instead of EC2-Classic, you
gain the ability to:
Assign static private IP addresses to your instances that persist
across starts and stops

EC2 Instances will not keep elastic IP

So, I don't understand what is going on here... I have (3) Micro EC2 Instances which are launched (without elastic ip)
I then go to Network Security->Elastic IPs and click associate IP address. I chose a running EC2 instance, that instance then uses the elastic ip.
If I stop, then start this SAME ec2 instance, it doesnt have the same previous elastic IP address and is instead some completely new IP address. This is messing up scripts that then depend on the previously associated elastic ip to that EC2 instance.
Why is this happening and why cant i get any of the (3) instances to adopt and keep this assigned elastic ip?
If you create a VPC and then re-provision the 3 micro instances under the VPC, EIPs you associate will remain associated during stop/start cycles. You won't be able to reuse your existing EC2 instances or EIPs; you'll have to recreate them under the new VPC.
Elastic IPs become disassociated with EC2 instances (in EC2-Classic) when you stop them. You will need to re-associate them again on startup, which can be done through the API (via AssociateAddress), CLI (via ec2-associate-address), or via the AWS Console.
Here's what the Elastic IP documentation has to say on the matter:
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. If you disassociate an EIP from the instance, the instance is
automatically assigned a new public IP address within a few minutes.
In addition, stopping the instance also disassociates the EIP from it.
We solve this at work by tagging our dev instances (which are turned off overnight) with the desired elastic IP and run a script in the morning to first turn them on, and then re-associate the elastic IP.
If you are willing to pay for NAT gateway (per hour charge + per GB traffic processed) , you can create a NAT gateway to make Elastic IP attach to your VPC private Subnet(you need to create route for subnet , point to nat-gateway, and modify your default route point to igw-id).
Any EC2 instance restart will have effect on the Elastic IP afterwards.