0 votes
1 view
in AWS by (16.7k points)

I want to detect if my code is getting executed in AWS Lambda environment. Is there a good, documented way to do it?

Currently, I'm depending on the existence of environmental variable LAMBDA_TASK_ROOT which was described in the Exploring The AWS Lambda Runtime Environment blog post which feels wrong

1 Answer

0 votes
by (39.6k points)

After the lambda entry point, you can set a Global variable or an Environment variable so that you can track manually. In node.js it is like this:

exports.handler = function(event, context, callback) {

    process.env['LAMBDA_ENV'] = 'true';

    ...

};

...