boto
(because I want to use --query
of ʻaws`)import commands
import re
def ipv4_address(instance_id):
query = "Reservations[].Instances[?InstanceId=='%(instance_id)s'].PublicIpAddress" % locals()
cmdline = 'aws ec2 describe-instances --query "%(query)s" --output text' % locals()
return commands.getoutput(cmdline)
def autoscaling_instance_ids(group):
query = "AutoScalingInstances[?AutoScalingGroupName=='%(group)s'].InstanceId" % locals()
result = commands.getoutput('aws autoscaling describe-auto-scaling-instances --query "%(query)s" --output text' % locals())
regexp = re.compile(r'\s+')
instance_ids = regexp.split(result)
return instance_ids
def ip_of_the_group(group):
ids = autoscaling_instance_ids(group)
return [ ipv4_address(instance_id) for instance_id in ids ]
Recommended Posts