'Retrieve AWS EC2 tags.'

@staticmethod
def get_tags(agentConfig):

    if (not agentConfig['collect_instance_metadata']):
        log.info('Instance    metadata    collection    is    disabled.    Not    collecting    it.')
        return []
    EC2_tags = []
    try:
        iam_role = EC2.get_iam_role()
        iam_url = ((EC2.METADATA_URL_BASE + '/iam/security-credentials/') + unicode(iam_role))
        r = requests.get(iam_url, timeout=EC2.TIMEOUT)
        r.raise_for_status()
        iam_params = r.json()
        r = requests.get(EC2.INSTANCE_IDENTITY_URL, timeout=EC2.TIMEOUT)
        r.raise_for_status()
        instance_identity = r.json()
        region = instance_identity['region']
        import boto.ec2
        proxy_settings = (get_proxy(agentConfig) or {})
        connection = boto.ec2.connect_to_region(region, aws_access_key_id=iam_params['AccessKeyId'], aws_secret_access_key=iam_params['SecretAccessKey'], security_token=iam_params['Token'], proxy=proxy_settings.get('host'), proxy_port=proxy_settings.get('port'), proxy_user=proxy_settings.get('user'), proxy_pass=proxy_settings.get('password'))
        tag_object = connection.get_all_tags({'resource-id': EC2.metadata['instance-id']})
        EC2_tags = [(u'%s:%s' % (tag.name, tag.value)) for tag in tag_object]
        if (agentConfig.get('collect_security_groups') and EC2.metadata.get('security-groups')):
            EC2_tags.append(u'security-group-name:{0}'.format(EC2.metadata.get('security-groups')))
    except EC2.NoIAMRole:
        log.warning(u'Unable    to    retrieve    AWS    EC2    custom    tags:    an    IAM    role    associated    with    the    instance    is    required')
    except Exception:
        log.exception('Problem    retrieving    custom    EC2    tags')
    return EC2_tags
