我需要在脚本中获取"当前用户" 的帐户IDboto3.到目前为止,我最好的解决方案是解析当前用户arn:
>>> import boto3
>>> account_id = boto3.resource('iam').CurrentUser().arn.split(':')[4]
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有更"轻量级"的方法.事实上
>>> timeit.timeit("boto3.resource('iam').CurrentUser().arn",
... 'import boto3', number=10)
4.8895583080002325
Run Code Online (Sandbox Code Playgroud)
我实际上不需要CurrentUser脚本中的资源.
mix*_*xja 71
您可以使用STS API获取帐户ID:
>>> import boto3
>>> boto3.client('sts').get_caller_identity().get('Account')
'012345678901'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19336 次 |
| 最近记录: |