0
votes

Using python boto3 library, I am using the ec2.create_instances function which returns the data shown below:

[ec2.Instance(id='i-34304930394309409')]

How do I simply extract the value for the id and put that into a another variable? I just want to retrieve "i-34304930394309409" and set that to a variable named "instanceid"

Is there a way to just call ec2.instance to retrieve this value?

1

1 Answers

0
votes

FYI: instance is the response returned from boto3 function of create_instances()

This is how I ended up solving the problem:

I created a variable called instance_id and then I set that to instance[0].id which is the first value in the list that matches the id string. Not sure if I am explaining that correctly...in any case:

instance_id = instance[0].id
print "Instance ID:", instance_id

This then prints the value I was looking to retrieve: "i-34304930394309409"