I use ipython to understand Boto3 and interact with EC2 instances. Here is the code I use to create the instance:
import boto3 ec2 = boto3.resource('ec2') client = boto3.client('ec2') new_instance = ec2.create_instances( ImageId='ami-d05e75b8', MinCount=1, MaxCount=1, InstanceType='t2.micro', KeyName=<name_of_my_key>, SecurityGroups=['<security_group_name>'], DryRun = False )
This starts the instance of EC2 instance, and I can get the public DNS name, ip and other information from the AWS console. But, when I try to get public DNS using Boto by doing this:
new_instance[0].public_dns_name
Returns empty quotation marks. However, other instance details, such as:
new_instance[0].instance_type
Returns the correct information.
Any ideas? Thank you
EDIT:
So if I do:
def get_name(inst): client = boto3.client('ec2') response = client.describe_instances(InstanceIds = [inst[0].instance_id]) foo = response['Reservations'][0]['Instances'][0]['NetworkInterfaces'][0]['Association']['PublicDnsName'] return foo foo = get_name(new_instance) print foo
Then it will return the public DNS. But it makes no sense to me why I should do all this.
python amazon-web-services dns boto3 aws-ec2
William Rudisill
source share