【问题标题】:How to make SSL-Requests with AWS-Lambda-Function?如何使用 AWS-Lambda-Function 发出 SSL 请求?
【发布时间】:2017-07-27 10:45:23
【问题描述】:

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

这是我的 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 日志文件中,我看到不支持 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 请求?如何解决?

【问题讨论】:

    标签: amazon-web-services ssl amazon-s3 lambda aws-lambda


    【解决方案1】:

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

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

    使用

    http = require('https');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      相关资源
      最近更新 更多