If you want to get the AWS Account ID of your Lambda Function while it is running then you can use the code below. The code below is written in Ruby.
Continue reading How to get AWS Account ID in Lambda using RubyTag: AWS Account ID
How to get the AWS Account ID in Lambda Node.js
To get the AWS Account ID of the currently running Lambda Function using Node.js use the code below.
exports.handler = async (event, context) => {
const awsAccountId = context.invokedFunctionArn.split(':')[4]
console.log(awsAccountId)
};
Continue reading How to get the AWS Account ID in Lambda Node.js How to get the AWS Account ID in Lambda Python
There are use cases where the need to get the AWS Account ID of the Lambda Function during runtime is required. I thought it was easy as getting the AWS Region but it was not. Luckily there is a way to get it, use the step-by-step instructions below.
To get the AWS Account ID where the Lambda Function is running use the code below.
def lambda_handler(event, context):
aws_account_id = context.invoked_function_arn.split(":")[4]
print(aws_account_id)
How does the code work?
The context
object that is being passed to the lambda_handler function provides different methods and properties about the lambda function, like invocation and execution environment.