Retrieving public dns of EC2 instance with BOTO3

Question:

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:

This starts an EC2 instance fine, and I can get the public DNS name, ip and other info from the AWS console. But, when I try to get the public DNS using Boto, by doing this:

Returns blank quotes. Yet, other instance details, such as:

Returns the correct information.

Any ideas? Thanks.

EDIT:

So if I do:

Then it will return the public DNS. But it doesn’t make sense to me why I need to do all of this.

Answer:

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.

Leave a Reply