I am trying to get AWS' VM list using Boto3's describe_instance
method. I am getting the following error.
Traceback (most recent call last):
File "pySkynet2.py", line 238, in <module>
skynet.execute()
File "pySkynet2.py", line 126, in execute
self.verify('build')
File "pySkynet2.py", line 77, in verify
vm_list = self.cloud_forge.get_vm_list()
File "/Users/ssrini358/workplace/Codes/COM_codes/Skynet/api2/cloudforge.py", line 952, in get_vm_list
instance = self.get_instance(auto_instance['Reservations'][0]['Instances'][0]['InstanceId'])
TypeError: string indices must be integers, not str
Following is the code snippet.
def get_vm_list(self):
"""
look up all the instances for the cluster (autoscaling_group)
:return: a list of associative arrays containing the instance_id, ip address and host name
"""
try:
instances = self.get_instances_for_autoscaling_group()
vms = []
for auto_instance in instances:
instance = self.get_instance(auto_instance['Reservations'][0],['Instances'][0],['InstanceId'])
host_name = ''
for tag in instance['Reservations'][0]['Instances'][0]['Tags']:
if tag['Key'] == 'Name':
host_name = tag['Value']
break
vms.append({'instance_id': instance['Reservations'][0]['Instances'][0]['InstanceId'],
'ip_addr': instance['Reservations'][0]['Instances'][0]['PrivateIpAddress'],
'host_name': host_name})
return vms
I have tried ['Reservations'][0], as well. But I am not able to get the instanceId. Kindly help TIA