I had difficulty implementing the other answers so I'm posting what worked for me.
In this case the function receives url, path and post data
Lambda function
var querystring = require('querystring');
var http = require('http');
exports.handler = function (event, context) {
var post_data = querystring.stringify(
event.body
);
// An object of options to indicate where to post to
var post_options = {
host: event.url,
port: '80',
path: event.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data)
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
context.succeed();
});
res.on('error', function (e) {
console.log("Got error: " + e.message);
context.done(null, 'FAILURE');
});
});
// post the data
post_req.write(post_data);
post_req.end();
}
Example of call parameters
{
"url": "example.com",
"path": "/apifunction",
"body": { "data": "your data"} <-- here your object
}