AWS Beanstalk Worker - Node.js Message format

时间:2015-10-30 22:42:31

标签: node.js amazon-web-services elastic-beanstalk

I'm in a place I get to too often with AWS. I'm figuring out how to use the worker app in Elastic Beanstalk. I have an express app set up to listen to a post. I put a message into my SQL queue. I get something in node, as I can trigger a message. But I have not idea how to get at the payload. As usual, I seem to be left grasping with AWS trying to glean the most basic of details from the documentation. If anyone can give me any pointers, I would much appreciate it. I'm basically just pasting some JSON into the message body on the AWS SQS console at this point in time. I have tried request.body and request.payload on the Node side - nothing.

This is the request that gets hit when the data comes - it's pretty simply. Should put into log. I've tried request.body, request.params, I get 'undefined'. I dumped out the entire request object here, and I'm not seeing it. As I don't know where it's supposed to be, I can't even tell whether it's my code, or it's just not there.

var stringify = require('json-stringify-safe');

function test(request, response, next)
{

    mainLog.log("info",stringify(request));

    respond_to_HTTP_request(response, null, null);;
}
exports.test = test;

2 个答案:

答案 0 :(得分:1)

设置并配置body-parser模块:

var bodyParser = require('body-parser'); app.use(bodyParser.json());

然后您的有效负载将在您的函数中可用:

var payload = request.body;

答案 1 :(得分:0)

var bodyParser = require('body-parser');
app.use(bodyParser.json());