node.js - NPM包 `pem`在AWS Lambda NodeJS 10.x中似乎不起作用(导致OpenSSL错误)

标签 node.js aws-lambda

当我在NodeJS 11.7.0上本地运行该函数时,它可以工作,当我在AWS Lambda NodeJS 8.10中运行它时,它可以工作,但是最近我尝试在AWS Lambda NodeJS 10.x中运行它,并在Cloud Watch中获得此响应和此错误。

关于如何更正此问题有任何想法吗?

响应

{
    "success": false,
    "error": "Error: Could not find openssl on your system on this path: openssl"
}

Cloudwatch错误
ERROR (node:8) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

函数
...
const util = require('util');
const pem = require('pem');
...

return new Promise((fulfill) => {
        require('./certs').get(req, res, () => {
            return fulfill();
        });
    }).then(() => {
        const createCSR = util.promisify(pem.createCSR);

        //This seems to be where the issue is coming from 
        return createCSR({
            keyBitsize: 1024,
            hash: HASH,
            commonName: id.toString(),
            country: 'US',
            state: 'Maryland',
            organization: 'ABC', //Obfuscated 
            organizationUnit: 'XYZ', //Obfuscated
        });
    }).then(({ csr, clientKey }) => {
        ...
    }).then(async ({ certificate, clientKey }) => {
        ...
    }, (err) => {
        return res.status(404).json({
            success: false,
            error: err,
        });
    });
...


我尝试过"pem": "^1.14.3","pem": "^1.14.2",

最佳答案

PEM NPM文档说:

Setting openssl location In some systems the openssl executable might not be available by the default name or it is not included in $PATH. In this case you can define the location of the executable yourself as a one time action after you have loaded the pem module:



因此,我认为它无法在系统中找到OpenSSL路径,您可以尝试以编程方式对其进行配置:
var pem = require('pem')
pem.config({
  pathOpenSSL: '/usr/local/bin/openssl'
}) 

当您使用AWS Lambda时,只需尝试打印process.env.path,您将了解路径路径env变量中是否包含OpenSSL。

您还可以通过运行以下代码来检查“OpenSSL”
const exec = require('child_process').exec;
exec('which openssl',function(err,stdopt,stderr){
      console.log(err ? err : stdopt);    
})

更新

正如@hoangdv在他的答案中提到的,openssl似乎已在node10.x运行时中删除,我认为他是对的。另外,我们对文件系统具有只读访问权限,因此我们不能做太多事情。

@Seth McClaine,您可以尝试使用node-forge npm模块。在此基础上构建的模块之一是“https://github.com/jfromaniello/selfsigned”,它将使您的任务更轻松

关于node.js - NPM包 `pem`在AWS Lambda NodeJS 10.x中似乎不起作用(导致OpenSSL错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58548580/

相关文章:

python - 在AWS lambda函数中使用scrapy作为层

amazon-web-services - 如何让 AWS Lambda 在 EBS 快照完成时触发

node.js - 如何在一台VPS服务器上运行多个独立的Loopback应用程序?

node.js - 基于 Node+react js 的企业级应用程序的最佳架构是什么?

javascript - meteor JS : Can not assign a variable

javascript - Auth0 授权者拒绝来自服务的 JWT token - "jwt issuer invalid. expected: https://myservice.auth0.com"

node.js - AWS Lambda 无法调用外部 https 端点

javascript - node js的gm包resizing image错误

node.js - 同步删除文件找不到文件

amazon-web-services - AWS API Gateway 自定义授权方日志