How can I get private IP adresses of all the instances which are part of an AutoScaling group. I am trying to do some operation on all the instances which are part of an autoscaling group.
How can I get private IP adresses of all the instances which are part of an AutoScaling group. I am trying to do some operation on all the instances which are part of an autoscaling group.
I have written a small script like below to get the IP list:
As alternative, my version without any jq/awk/sed/cut
More optimized version
If you need just a plain list in the output you can add another pipeline
| jq -r '.[]'
Take a look at the fine documentation for the AWS API. E.g. the aws-cli tools aws autoscaling describe-auto-scaling-instances and aws ec2 describe-instances.
Similar to Ramesh's answer here is a nice little script based on the current instance and its group. Make sure to set your region and in this case I skip the current instance (used for clustering). You can also change PrivateIpAddress to Public if required.
you can also use
jq
to parse the output, it is a bad idea to use awk, grep, or sed, etc, to parse a node structure, similar to it being a bad idea to use regular expressions to parse html.You can also look in AWS web console UI under EC2 -> Auto Scaling Groups -> Instances Tab. You will see all the instances under current ASG, you can then click on each instance-ID to get the IP(It will redirect you to different view.)
This will return all of the private ips of instances in an ASG
Use a unique tag for your AutoScaling and check the option apply on Instances.
For i.e. Key: Prod Value: Server
Your AutoScaling instances will have this unique Tag. Run this below command to list all PrivateIP address: