How to get the public ip's using boto3
<p>I need to extract all the RUNNING PUBLIC Ip's from AWS and i am using the following code:</p>

<pre><code>def gather_public_ip():
    regions = ['us-west-2', 'eu-central-1', 'ap-southeast-1']
    combined_list = []   ##This needs to be returned
    for region in regions:
        instance_information = [] # I assume this is a list, not dict
        ip_dict = {}
        client = boto3.client('ec2', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY,
                              region_name=region, )
        instance_dict = client.describe_instances().get('Reservations')
        for reservation in instance_dict:
            for instance in reservation['Instances']: # This is rather not obvious
               if instance[unicode('State')][unicode('Name')] == 'running' and instance[unicode('PublicIpAddress')] != None:
                    ipaddress = instance[unicode('PublicIpAddress')]
                    tagValue = instance[unicode('Tags')][0][unicode('Value')] # 'Tags' is a list, took the first element, you might wanna switch this
                    zone = instance[unicode('Placement')][unicode('AvailabilityZone')]
                    info = ipaddress, tagValue, zone
                    instance_information.append(info)
        combined_list.append(instance_information)
    return combined_list
</code></pre>

<p>This is not working out for me , and it gives me the error :</p>

<pre><code>    ipaddress = instance[unicode('PublicIpAddress')]
KeyError: u'PublicIpAddress'
</code></pre>

<p>The reason being <code>PublicIpAddress</code> doesn't exists in this dict.. Can someone please help me out ?</p>