winston.xie
winston.xie

Reputation: 81

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.

Upvotes: 0

Views: 1811

Answers (2)

John Rotenstein
John Rotenstein

Reputation: 269141

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.)

Upvotes: 3

Deepak Singhal
Deepak Singhal

Reputation: 10866

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.

Upvotes: 1

Related Questions