How to Get Account Number From AWS Lambda


If you need to get the current Account Number, or Account ID from within a Lambda execution, then you can access invoked_function_arn from the context and return the associated value as follows:

aws_account_id = context.invoked_function_arn.split(":")[4]