如何使用 AWS-Lambda-Function 发出 SSL 请求?

巡视

我有一个 AWS-Lambda 函数,它在将文件放入 S3-Bucket 后触发。

这是我的 lambda 函数:

var http = require('http');

exports.handler = function (event, context) {

 var bucket = event.Records[0].s3.bucket.name;
 var key = event.Records[0].s3.object.key;

 var newKey = key.split('.')[0].slice(8);

 var url = 'https://xxxxx.herokuapp.com/api/messages/'+newKey+'/processingFinished'
 console.log("URL:" + url)

  http.get(url, function (result) {
    console.log('!!!! Success, with: ' + result.statusCode);
    context.done(null);
  }).on('error', function (err) {
    console.log('Error, with: ' + err.message);
    context.done("Failed");
  });
};

在 CloudWatch Logfiles 中,我看到不支持 https 的抱怨:

2017-07-27T10:38:04.735Z    8428136e-72b7-11e7-a5b9-bd0562c862a0    Error: Protocol "https:" not supported. Expected "http:"
at new ClientRequest (_http_client.js:54:11)
at Object.exports.request (http.js:31:10)
at Object.exports.get (http.js:35:21)
at exports.handler (/var/task/index.js:18:8)

但是列出的 URL 可以使用任何网络浏览器打开。服务器接受 SSL,整个 API 都按照 SSL 工作。

为什么 AWS 拒绝 SSL 请求?如何解决这个问题?

富金医学博士

根据节点文档:(https://nodejs.org/api/https.html

HTTPS 是基于 TLS/SSL 的 HTTP 协议。在 Node.js 中,这是作为一个单独的模块实现的。

http = require('https');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章