AWS LAMBDA获取上下文信息上下文、信息、AWS、LAMBDA

2023-09-11 11:33:53 作者:怪味小萝莉

我使用从AWS控制台的测试功能:

I am using the test function from AWS console:

console.log('Loading event');

exports.handler = function(event, context) {
    console.log('value1 = ' + event.key1);
    console.log('value2 = ' + event.key2);
    console.log('value3 = ' + event.key3);
    context.done(null, 'Hello World');  // SUCCESS with message
};

和调用它在nodejs如下:

And calling it in nodejs as follows:

var params = {
  FunctionName: 'MY_FUNCTION_NAME', /* required */
  InvokeArgs: JSON.stringify({
    "key1": "value1",
    "key2": "value2",
    "key3": "value3"
  })
};

lambda.invokeAsync(params, function(err, data) {
  if (err) {
    // an error occurred
    console.log(err, err.stack);
    return cb(err);
  }
  // successful response
  console.log(data);
});

和一切工作正常:

//Console Output
{ Status: 202 }

不过,我期待从context.done接收消息(NULL,邮件),以及...

But I was expecting to receive the message from context.done(null, 'Message') as well...

不知道如何得到的消息?

Any idea how to get the message?

推荐答案

正如埃里克提到,目前LAMBDA不提供REST端点运行的功能,并返回它的结果,但可能在未来。

As Eric mentioned, currently Lambda doesn't offer a REST endpoint to run the function and return its result, but may in the future.

现在,最好的办法是使用一个库如 lambdaws ,它包装的功能配置和执行为您和手柄通过SQS队列返回结果。如果您想了解更多的控制通过滚动自己的解决方案,这个过程很简单:

Right now, your best bet would be to use a library like lambdaws, which wraps the function deployment and execution for you and handles returning results via an SQS queue. If you'd like more control by rolling your own solution, the process is straightforward:

创建一个SQS队列 让您的lambda函数写它的结果到此队列 在您的客户端,查询队列结果
 
精彩推荐
图片推荐