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 Answer
1
Accepted Answer

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
EXPERT
Kallu
answered a year ago
profile pictureAWS
EXPERT
iBehr
reviewed 10 months ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions