[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"]