def get_instance_identity(version='latest', url='http://169.254.169.254', timeout=None, num_retries=5):
 iid = {}
 base_url = _build_instance_metadata_url(url, version, 'dynamic/instance-identity/')
 try:
  data = retry_url(base_url, num_retries=num_retries, timeout=timeout)
  fields = data.split('\n')
  for field in fields:
   val = retry_url((((base_url + '/') + field) + '/'), num_retries=num_retries, timeout=timeout)
   if (val[0] == '{'):
    val = json.loads(val)
   if field:
    iid[field] = val
  return iid
 except urllib.error.URLError:
  return None

def get_instance_identity ( version = 'latest' , url = 'http://169.254.169.254' , timeout = None , num_retries = 5 ) : iid = { } base_url = _build_instance_metadata_url ( url , version , 'dynamic/instance-identity/' ) try : data = retry_url ( base_url , num_retries = num_retries , timeout = timeout ) fields = data . split ( '\n' ) for field in fields : val = retry_url ( ( ( ( base_url + '/' ) + field ) + '/' ) , num_retries = num_retries , timeout = timeout ) if ( val [ 0 ] == '{' ) : val = json . loads ( val ) if field : iid [ field ] = val return iid except urllib . error . URLError : return None
returns the instance identity as a nested python dictionary .