2017-11-29 5 views

答えて

0

このコードを使用して、インスタンスIDとプライベートIPアドレス をASGから印刷します。私はそれが助けて欲しい

asg_client = boto3.client('autoscaling',aws_access_key_id=acc_key,aws_secret_access_key=sec_key,region_name='us-west-2') 

asg = "YOUR_ASG_NAME" 
print asg 
asg_response = asg_client.describe_auto_scaling_groups(AutoScalingGroupNames=[asg]) 

instance_ids = [] # List to hold the instance-ids 

for i in asg_response['AutoScalingGroups']: 
    for k in i['Instances']: 
     instance_ids.append(k['InstanceId']) 

ec2_response = ec2_client.describe_instances(
     InstanceIds = instance_ids 
     ) 
print instance_ids #This line will print the instance_ids 

private_ip = [] # List to hold the Private IP Address 

for instances in ec2_response['Reservations']: 
    for ip in instances['Instances']: 
     private_ip.append(ip['PrivateIpAddress']) 


print "\n".join(private_ip) 
関連する問題