2

My website is running behind an AWS Classic Load Balancer. It has some scaling policies and it launches some new EC2 instances when it has to.

Is it possible to have the range of public IP addresses that will be used for the EC2 instances when they will be launched by the load balancer ?

Djagu
  • 163
  • 1
  • 12
  • What do you mean, *"used for the instances?"* For outgoing requests from the instances to (e.g.) 3rd party APIs? If so, yes: https://serverfault.com/q/759998/153161 – Michael - sqlbot Mar 07 '18 at 12:23

2 Answers2

0

Is it possible to have the range of public IP addresses that will be used for the EC2 instances when they will be launched by the load balancer

Not to my knowledge. Public IP addresses are assigned automatically by AWS from a pool of addresses and I do not believe it is possible to know in advance what address will be assigned to your EC2.

See here for more details

Why do you need the ip address of the new instances, out of interest? Are you trying to dynamically provision access to resources on them as part of your ec2 startup process?

mcfinnigan
  • 11,442
  • 35
  • 28
  • I need all my instances to access an API which is restricted to certain ip addresses only. – Djagu Mar 06 '18 at 11:33
  • put the API behind an ALB or Network load balancer, and permit access to that load balancer from your classic load balancer via security groups. AWS does not guarantee the permanence of allocated IP addresses and using these for access control is a potential point of failure. – mcfinnigan Mar 06 '18 at 11:51
  • The API is not internal to my architecture. It is handled by another company and they need to whitelist my servers ip addresses to grant me access to their service. – Djagu Mar 06 '18 at 12:00
0

This is technically possible if you use Elastic IPs. While you can't create a pool for your scaling policies to pull from, you can create several EIPs and configure Lambda scripts that trigger during scaling events, and assign available EIPs to the new instances using the associateAddress API.

Alternatively, this seems like a similar problem, and maybe a useful solution for you.

MrDuk
  • 16,578
  • 18
  • 74
  • 133