getting the current user account-id in boto3

You can get the account ID by using the STS API:

>>> import boto3
>>> boto3.client('sts').get_caller_identity().get('Account')
'012345678901'

EDIT: There is now an api you can call, see mixja's answer.

First off, there is no way to get the account id straight from boto3. There is no information stored locally that can tell you that, and there is no service API that returns it outside the context of an ARN. So there is no way to get it from boto3 without inspecting an ARN.

Secondly, using timeit can be very misleading with boto3 or botocore because there is a bit of warm-up time when you create a client or resource for the first time (the service definitions are loaded on the fly).

Tags:

Boto3

Botocore