【问题标题】:How to create a HarperDB table with lambda如何使用 lambda 创建 HarperDB 表
【发布时间】:2021-10-12 20:29:00
【问题描述】:

我编写了以下 Node.js 代码来在 HarperDB Cloud 上创建一个表。此代码在本地执行时完美执行。我将相同的代码移动到AWS Lambda,唉,代码执行没有任何错误,但表没有被创建。

我怀疑我调用 lambda 函数的方式有问题,但我无法找出问题所在。我该如何解决?


exports.handler = async (event,) => {

  var https = require('follow-redirects').https;
  var fs = require('fs');

  var options = {
    'method': 'POST',
    'hostname': 'MyInstanceName-MyAccount.harperdbcloud.com',
    'path': '/',
    'headers': {
      'Authorization': 'Basic MyAuthoriztionCode',
      'Content-Type': 'application/json'
    },
    'maxRedirects': 20
  };

  var req = https.request(options, function (res) {
    var chunks = [];

    res.on("data", function (chunk) {
      chunks.push(chunk);
    });

    res.on("end", function (chunk) {
      var body = Buffer.concat(chunks);
      console.log(body.toString());
    });

    res.on("error", function (error) {
      console.error(error);
    });
  });

  var postData = JSON.stringify({
    "operation": "create_table",
    "schema": "MySchema",
    "table": "NewTable",
    "hash_attribute": "Id"
  });

  req.write(postData);
  req.end();

  const response = {
      statusCode: 200,
      body: JSON.stringify('Table created successfully!'),
  };

  return response;

};

/// AWS Lambda Function (Node.js code) ends here'''

【问题讨论】:

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


【解决方案1】:

我相信这是因为您在异步 lambda 处理程序中使用了回调。

尝试将 lambda 转换为回调

exports.handler = (event, context, callback) => {}

或使用异步/等待请求库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多