AWS LAMBDA获取上下文信息 [英] AWS Lambda get context message

查看:429
本文介绍了AWS LAMBDA获取上下文信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从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:

  1. 创建一个SQS队列
  2. 让您的lambda函数写它的结果到此队列
  3. 在您的客户端,查询队列结果

这篇关于AWS LAMBDA获取上下文信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆