I'm trying to post data from a the OData RESTful API from a sample service used which is the TripPin. The request succeeded but the response est null. Is there any particular structure to respect in AWS Lambda platform in order to make HTTP post request?
var querystring = require('querystring');
var http = require('http');
exports.handler = function (event, context) {
var post_data = querystring.stringify(
{
UserName:'lewisblack',
FirstName:'Lewis',
LastName:'Black',
Emails:[
'[email protected]'
],
AddressInfo:[
{
Address: '187 Suffolk Ln.',
City: {
CountryRegion: 'United States',
Name: 'Boise',
Region: 'ID'
}
}
],
Gender: 'Male'
}
);
// 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);
console.log("hello");
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": "services.odata.org",
"path": "/v4/TripPinServiceRW/"
}
Response: null
Request ID: "6f1ec2b4-5195-477f-9fb8-56fd33dee0ce"
Function Logs: START RequestId: 6f1ec2b4-5195-477f-9fb8-56fd33dee0ce Version: $LATEST
END RequestId: 6f1ec2b4-5195-477fenter code here
-9fb8-56fd33dee0ce
REPORT RequestId: 6f1ec2b4-5195-477f-9fb8-56fd33dee0ce Duration: 431.87 ms
Billed Duration: 500 ms Memory Size: 128 MB Max Memory Used: 73 MB