I\'m using ipython to get an understanding of Boto3 and interacting with EC2 instances. Here is the code I\'m using to create an instance:
import boto3
ec2 = bo
The Instance
object you get back is only hydrated with the response attributes from the create_instances
call. Since the DNS name is not available until the instance has reached the running state [1], it will not be immediately present. I imagine the time between you creating the instance and calling describe instances is long enough for the micro instance to start.
import boto3
ec2 = boto3.resource('ec2')
instances = ec2.create_instances(
ImageId='ami-f0091d91',
MinCount=1,
MaxCount=1,
InstanceType='t2.micro',
KeyName='',
SecurityGroups=[''])
instance = instances[0]
# Wait for the instance to enter the running state
instance.wait_until_running()
# Reload the instance attributes
instance.load()
print(instance.public_dns_name)