Start NodeJS runtime in AWS lambda with a specific option or environment variable

Viewed 1606

Getting NodeJS deprecation error when execute an AWS Lambda (using node 12.x):

[DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated

can not find which module/piece of code is producing it. Nothing seems to reference _headers or _headerNames.

In Node should be possible to set a parameter or environment variable as explain here to --trace-deprecation and/or --trace-warnings and/or --throw-deprecation. When setting one or multiple of these values in AWS Console Environment variables for the lambda, no extra information is displayed.

AWS lambda environment variables

What is the way to set this runtime parameter for an AWS Lambda? Is there a way to catch the stack trace to know where is the deprecated error happening?

1 Answers

feliz de ayudar! I pasted the snippet for the future.

set the flag in webpack.config.js code as explained here

process.traceDeprecation = true;

module.exports = {
  // Your config
};

If the deprecation error is in a function you can do: (even any defeats purpose of Typescript, is just for locating the problem, to be removed after)

(process as any).traceDeprecation = true;

also can check the value

exports.handler = async (event) => {
    console.log( 'process.traceDeprecation', process.traceDeprecation );
    Buffer(1);
    process.on('warning', (warning) => {
        console.log( 'stack of deprecation' );
        console.log(warning.stack);
    });    
};

Thanks!

Related