stackUser67
stackUser67

Reputation: 128

To log Lambda function name in cloudwatch

Is there any possible way to log the name of the Lambda in CloudWatch ?

Ex:

START RequestId: 4b453a3-f239-461f-94ab-ebesdfsdb04de Version: $LATEST

The "RequestId" is already getting logged. Any property I can use to log the name of the lambda as well ?

I don't want an explicit console.log statement but a property/parameter which directly gives out my lambda's name along with START , END and INFO fields.

Upvotes: 1

Views: 955

Answers (3)

mkrana
mkrana

Reputation: 430

You should be using context property (function_name).

def lambda_handler(event, context):
    print("lambda function: {}".format(context.function_name)) 

Please refer below link for more details.

Upvotes: 1

Ashish Modi
Ashish Modi

Reputation: 7770

could do this in nodejs

console.log(process.env.AWS_LAMBDA_FUNCTION_NAME)

Upvotes: 0

shuvalov
shuvalov

Reputation: 4913

You coud use environment variable AWS_LAMBDA_FUNCTION_NAME (see full list). If your Lambda are written on Python it could looks like this:

import os

def lambda_handler(event, context):
    print("Running function '%s'" % os.environ.get('AWS_LAMBDA_FUNCTION_NAME', None))

Upvotes: 0

Related Questions