'Get credentials from IAM authentication'

def role_config(self):

    try:
        conn = httplib.HTTPConnection(host='169.254.169.254', timeout=2)
        conn.request('GET', '/latest/meta-data/iam/security-credentials/')
        resp = conn.getresponse()
        files = resp.read()
        if ((resp.status == 200) and (len(files) > 1)):
            conn.request('GET', ('/latest/meta-data/iam/security-credentials/%s' % files))
            resp = conn.getresponse()
            if (resp.status == 200):
                creds = json.load(resp)
                Config().update_option('access_key', creds['AccessKeyId'].encode('ascii'))
                Config().update_option('secret_key', creds['SecretAccessKey'].encode('ascii'))
                Config().update_option('access_token', creds['Token'].encode('ascii'))
            else:
                raise IOError
        else:
            raise IOError
    except:
        raise
