当我在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/