Reputation: 224
Good day,
I am very new to Coding/Python so please give the answers like your speaking to a stupid person...I definitely won't be offended.
I am able to launch an ec2 instance successfully but I would like a way to see the details of the instance that I just launched. I would like to get back any kind of info such as the instance ID, IP address or anything like that. Here is what I have so far:
#!/usr/bin/python
###Import the following arguments for the script
from sys import argv
script, base_ami, package = argv
print "Just launching a copy of", base_ami,"..."
import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1",
aws_access_key_id='<key>',
aws_secret_access_key='<secret>')
conn.run_instances('ami-df091bb6')
How do I find some info on the instance that I just launched?
Thanks
Upvotes: 0
Views: 1689
Reputation: 61521
You first need to get the reservation
object when you run your instance and from the reservation you can get the instance object. Once you get instance object you can query it but just calling its attributes. The conn.run_instances
method returns its current reservation so you can just do as follows:
#!/usr/bin/python
###Import the following arguments for the script
from sys import argv
script, base_ami, package = argv
print "Just launching a copy of", base_ami,"..."
import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1",
aws_access_key_id='<key>',
aws_secret_access_key='<secret>')
reservation = conn.run_instances('ami-df091bb6')
myinstance = reservation.instances[0]
# The get the instance id
myid = instance.id
Upvotes: 2