Node.js 如何使用AWS Lambda调用安全路由?

Node.js 如何使用AWS Lambda调用安全路由?,node.js,amazon-web-services,ssl,lambda,Node.js,Amazon Web Services,Ssl,Lambda,这是AWS Lambda函数的代码部分。当我在非SSL的登台环境中使用它时,它工作得很好 我尝试使用stackoverflow post的答案,但我收到一个npm错误,无法找到包ssl根CA,并且我不完全确定是否能够安装节点包 'use strict'; const https = require('https'); var rootCas = require('ssl-root-cas').create(); https.globalAgent.options.ca = rootCas;

这是AWS Lambda函数的代码部分。当我在非SSL的登台环境中使用它时,它工作得很好

我尝试使用stackoverflow post的答案,但我收到一个npm错误,无法找到包ssl根CA,并且我不完全确定是否能够安装节点包

'use strict';

const https = require('https');

var rootCas = require('ssl-root-cas').create();

https.globalAgent.options.ca = rootCas;

/**
 * Pass the data to send as `event.data`, and the request options as
 * `event.options`. For more information see the HTTPS module documentation
 * at https://nodejs.org/api/https.html.
 *
 * Will succeed with the response body.
 */
exports.handler = (event, context, callback) => {

    var url = 'https://admin.domain.com/api/schedule/checkForPublishedScreeners?authentication_token=mytoken';
    https.get(url, (res) => {

        let body = '';
        console.log('Status:', res.statusCode);
        console.log('Headers:', JSON.stringify(res.headers));
        res.setEncoding('utf8');
        res.on('data', (chunk) => body += chunk);
        res.on('end', () => {
            console.log('Successfully processed HTTPS response');
            // If we know it's JSON, parse it
            if (res.headers['content-type'] === 'application/json') {
                body = JSON.parse(body);
            }
            callback(null, body);
        });

    }).on('error', (e) => {
        console.error(e);
    });
};

您需要在package.json中包含ssl根CA,并在发布lambda代码时包含它

npm init -y
npm install --save ssl-root-cas

将node_模块与lambda代码一起压缩,然后将其发布到lambda

我实际上没有提交package.json,例如,我从不在require'https'行中包含任何内容。也许我在Lambda实现中遗漏了什么?https模块内置在NodeJS Lambda运行时中。ssl根CA模块不是。您需要在压缩和上载的节点\ U模块中包含ssl根CA。