getting the current user account-id in boto3

前端 未结 2 1320
花落未央
花落未央 2020-12-14 06:27

I need to get the account-id of the \'current user\' in a boto3 script. Up to now my best solution is to parse the current user arn:

>>> import boto         


        
2条回答
  •  轮回少年
    2020-12-14 06:52

    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).

提交回复
热议问题