无法调用 Lambda 函数 AWS

Can't invoke Lambda function AWS

我在 node.js 中的 Lambda 函数:

console.log('Loading function');

  exports.handler = function(event, context) {

  console.log('value1 =', event.key1);
  context.succeed("Hello " + event.key1);
  };

我希望客户端(我的笔记本电脑)将包含值 "world" 的对象发送到此 lambda 函数。该函数添加 "Hello " 和 returns "Hello world"。 我使用带有 curl 的 cmd 和以下语句:

curl -X POST -d '{"key1":"world"}' https://blablablabla.execute-api.us-west-2.amazonaws.com/prod/helloworld2

但我只回来了{"message":"internal server error"}

有什么想法吗?还有其他方法可以发送 "world" 值吗?也许是 html 文件中的 java 脚本或 Eclipse 中的简单 java 应用程序? lambda 函数本身很好。我通过测试事件成功测试了它。

你的功能似乎没问题。但是您在 cURL 命令中缺少 Content-Type header 。如下操作:

curl -H "Content-Type: application/json" -X POST -d "{\"key1\": \"World\"}" https://blablablabla.execute-api.us-west-2.amazonaws.com/prod/helloworld2

您可以在 this AWS documentation.

中仔细检查此要求

更新:试试这个函数(我只添加了回调参数)

'use strict';
console.log('Loading function');

exports.handler = function(event, context, callback) {
    console.log('value1 =', event.key1);
    callback(null, {"Hello": event.key1});
};