【问题标题】:AWS Lambda openssl x509 error with Node.js 12.xAWS Lambda openssl x509 Node.js 12.x 错误
【发布时间】:2020-01-08 17:15:17
【问题描述】:

我正在尝试运行以下代码以使用 openssl 读取证书。该代码能够在 Node.js 8.10 的 Lambda 上运行。

const util = require('util');
const exec = util.promisify(require('child_process').exec);

var pemCert = "testCert.cer";

exports.handler = async (event) => {
    return execute('Get Public Key Issuer', 'openssl x509 -in ' + pemCert + ' -noout -issuer -nameopt multiline | grep organizationName')
    .then(result => {
        return (result);
    }).catch(error => {
        console.log (error);
    });
};

async function execute(purpose, command) {
    try {
        const {
            stdout,
            stderr
        } = await exec(command);
        console.log(purpose + " : " + command);
        console.log('Execute stdout:', stdout);
        return stdout;
    } catch (error) {
        console.log(purpose + " : " + command);
        console.log("Error:" + error);
        throw (purpose + " failed.");
    }
}

但是,在将 Lambda 与 Node.js 12.x 一起使用时,我收到以下错误:

/bin/sh: openssl: command not found

AWS 在新 Node.js 的运行时似乎不支持 openssl 是否有任何替代方案可用于在节点 12 上的 Lambda 中执行 openssl 命令?

【问题讨论】:

  • 将路径更改为:__dirname + '/openSSL/openssl x509 -in ' 似乎已经解决了这个问题。

标签: node.js amazon-web-services aws-lambda openssl


【解决方案1】:

引用 AWS 发送的电子邮件

“我们正在更新 AWS Lambda 和 AWS Lambda@Edge 执行环境,以包括最新版本的 Amazon Linux 和软件包。

大多数功能将无缝受益于本次更新中的增强功能,无需您采取任何措施。但是,在极少数情况下,软件包更新可能会引入兼容性问题。包含针对非常特定的底层操作系统包编译的库或应用程序代码的函数,特别是那些用于 openssl、glibc 或其他系统库的函数,可能会受到影响。

从 2019 年 5 月 14 日开始,您可以使用新的执行环境测试您的函数。从 2019 年 5 月 21 日起,所有新功能或现有功能的更新都将使用新的执行环境。您现有的函数将在 2019 年 6 月 11 日自动迁移到使用新的执行环境。”

另一种选择是使用 AWS Lambda 层 (https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)

您可以在此处查看详细步骤-NPM package `pem` doesn't seem to work in AWS lambda NodeJS 10.x (results in OpenSSL error)

【讨论】:

    猜你喜欢
    • 2020-10-06
    • 1970-01-01
    • 2020-11-20
    • 2021-01-28
    • 1970-01-01
    • 2021-07-24
    • 2021-07-25
    • 1970-01-01
    • 2022-09-30
    相关资源
    最近更新 更多