使用特定选项或环境变量在 AWS lambda 中启动 NodeJS 运行时

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

执行 AWS Lambda 时出现 NodeJS 弃用错误(使用节点 12.x):

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

找不到生成它的 module/piece 代码。似乎没有任何内容提及 _headers or _headerNames

在 Node 中应该可以将参数或环境变量设置为 explain here--trace-deprecation and/or --trace-warnings and/or --throw-deprecation。在 lambda 的 AWS 控制台环境变量中设置这些值中的一个或多个时,不会显示额外信息。

为 AWS Lambda 设置此运行时参数的方法是什么?有没有办法捕获堆栈跟踪以了解已弃用的错误发生在哪里?

大吉大利!我粘贴了未来的片段。

按照说明在 webpack.config.js 代码中设置标志 here

process.traceDeprecation = true;

module.exports = {
  // Your config
};

如果弃用错误在一个函数中你可以这样做:(即使any打败了Typescript的目的,只是为了定位问题,之后被删除)

(process as any).traceDeprecation = true;

也可以查看值

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);
    });    
};

谢谢!