【发布时间】:2019-02-22 21:08:00
【问题描述】:
我需要在boto3 脚本中获取“当前用户”的account-id。到目前为止我最好的解决方案是解析当前用户arn:
>>> import boto3
>>> account_id = boto3.resource('iam').CurrentUser().arn.split(':')[4]
但我想知道是否有更“轻量级”的方法。其实
>>> timeit.timeit("boto3.resource('iam').CurrentUser().arn",
... 'import boto3', number=10)
4.8895583080002325
实际上我的脚本中不需要CurrentUser 资源。
【问题讨论】: