How can I retrieve an available IP address given a Subnet ID?

0

I am trying to create a Target Group via AWS CloudFormation. Its TargetType is ip, and therefore I must register targets by IP address. In this link, it says that I can specify IP addresses from the subnets of the virtual private cloud (VPC) for the target group.

I want to use an available (i.e., assignable) IP address from the Subnet with the Subnet ID of, say, subnet-0cd123152. However, Subnet does not return assignable IP addresses.

Is there any way that I can retrieve an available IP address, given the Subnet ID? Or, is there any possible way manage to specify the Targets without explicitly retrieving the IP address from the Subnet?

1 Risposta
1
Risposta accettata

I think you are trying to do this backwards. Instead of registering random available IP addresses from the subnet, you should first create the resource you want to access via load balancer and then register IP of the resource to target group. Typically when using EC2 instances, you want to register them with instance ID (not IP) but IP would allow attaching other resources like databases and on-prem resources. See https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html

profile picture
ESPERTO
Kallu
con risposta un anno fa
profile pictureAWS
ESPERTO
iBehr
verificato un anno fa
  • Thanks for your advice. Actually, I've just figured out that I can just leave Targets empty, and it works. Of course, as you've said, I first created AWS::ECS::Service and set TargetGroupArn in LoadBalancers as the target group that I mentioned. This way, the target IP is automatically registered.

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande