NPM包"pem"在AWS Lambda NodeJS 10.x中似乎不起作用(导致OpenSSL错误) [英] NPM package `pem` doesn't seem to work in AWS lambda NodeJS 10.x (results in OpenSSL error)

查看:112
本文介绍了NPM包"pem"在AWS Lambda NodeJS 10.x中似乎不起作用(导致OpenSSL错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I run the function locally on NodeJS 11.7.0 it works, when I run it in AWS Lambda NodeJS 8.10 it works, but I've recently tried to run it in AWS Lambda NodeJS 10.x and get this response and this error in Cloud Watch.

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

Any thoughts on how to correct this?

回复

{
    "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文档说:

设置openssl位置 在某些系统中,默认名称可能无法提供openssl可执行文件,或者它不包含在$ PATH中.在这种情况下,您可以在加载了pem模块之后将自己的可执行文件的位置定义为一次性操作:

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路径,您可以尝试以编程方式对其进行配置:

So I think it is not able to find OpenSSL path in system you can try configuring it programmatically :

var pem = require('pem')
pem.config({
  pathOpenSSL: '/usr/local/bin/openssl'
}) 

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

As you are using AWS Lambda so just try printing process.env.path you will get idea of whether OpenSSL is included in path env variable or not.

您还可以通过运行以下代码

You can also check 'OpenSSL' by running below code

const exec = require('child_process').exec;
exec('which openssl',function(err,stdopt,stderr){
      console.log(err ? err : stdopt);    
})

更新

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

As @hoangdv mentioned in his answer openssl is seems to be removed for node10.x runtime and I think he is right. Also, we have read-only access to file system so we can't do much.

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

@Seth McClaine, you can give try for node-forge npm module. One of the module built on top of this is 'https://github.com/jfromaniello/selfsigned' which will make your task easier

这篇关于NPM包"pem"在AWS Lambda NodeJS 10.x中似乎不起作用(导致OpenSSL错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆