[AWS] Lambda Python Get Current Account Id


Unlike AWS_REGION or AWS_LAMBDA_FUNCTION_NAME, we cannot get current account id from the environment variables. In order to to get the account id, we can use boto3 library with the following code:


import boto3

client = boto3.client("sts")
account_id =  client.get_caller_identity()["Account"]
posted @ 2022-09-03 13:56  Grandyang  阅读(71)  评论(0编辑  收藏  举报
Fork me on GitHub