CargoMeister
CargoMeister

Reputation: 4309

AWS Beanstalk Worker - Node.js Message format

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;

Upvotes: 2

Views: 510

Answers (2)

Ellery Familia
Ellery Familia

Reputation: 539

Setup and configure the body-parser module:

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

then your payload will be available within your function:

var payload = request.body;

Upvotes: 1

Dylan Bathurst
Dylan Bathurst

Reputation: 109

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

Upvotes: 0

Related Questions