def get_account_id(region=None, key=None, keyid=None, profile=None):
 cache_key = 'boto_iam.account_id'
 if (cache_key not in __context__):
  conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
  try:
   ret = conn.get_user()
   arn = ret['get_user_response']['get_user_result']['user']['arn']
   account_id = arn.split(':')[4]
  except boto.exception.BotoServerError:
   timeout = boto.config.getfloat('Boto', 'metadata_service_timeout', 1.0)
   attempts = boto.config.getint('Boto', 'metadata_service_num_attempts', 1)
   identity = boto.utils.get_instance_identity(timeout=timeout, num_retries=attempts)
   try:
    account_id = identity['document']['accountId']
   except KeyError:
    log.error('Failed to get account id from instance_identity in boto_iam.get_account_id.')
  __context__[cache_key] = account_id
 return __context__[cache_key]

def get_account_id ( region = None , key = None , keyid = None , profile = None ) : cache_key = 'boto_iam.account_id' if ( cache_key not in __context__ ) : conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) try : ret = conn . get_user ( ) arn = ret [ 'get_user_response' ] [ 'get_user_result' ] [ 'user' ] [ 'arn' ] account_id = arn . split ( ':' ) [ 4 ] except boto . exception . BotoServerError : timeout = boto . config . getfloat ( 'Boto' , 'metadata_service_timeout' , 1.0 ) attempts = boto . config . getint ( 'Boto' , 'metadata_service_num_attempts' , 1 ) identity = boto . utils . get_instance_identity ( timeout = timeout , num_retries = attempts ) try : account_id = identity [ 'document' ] [ 'accountId' ] except KeyError : log . error ( 'Failed to get account id from instance_identity in boto_iam.get_account_id.' ) __context__ [ cache_key ] = account_id return __context__ [ cache_key ]
retrieve the aws account id for the authenticated user or role .