amazon web services - AWS Lambda http request: Unable to stringify body as json: Converting circular structure to JSON -
i return result of http request in aws lambda function:
var http = require('http'); exports.somefunction = function(event, context) { var url = "http://router.project-osrm.org/trip?loc=47.95,12.95&loc=47.94,12.94"; http.get(url, function(res) { context.succeed(res); }).on('error', function(e) { context.fail("got error: " + e.message); }); }
it should return when open url directly in browser (try see expected json).
aws lambda return following error message when call context.succeed(res)
:
{ "errormessage": "unable stringify body json: converting circular structure json", "errortype": "typeerror" }
i assume need use property of res
instead of res
itself, couldn't figure out 1 contains actual data want.
if using raw http
module need listen data
, end
events.
exports.somefunction = function(event, context) { var url = "http://router.project-osrm.org/trip?loc=47.95,12.95&loc=47.94,12.94"; http.get(url, function(res) { // continuously update stream data var body = ''; res.on('data', function(d) { body += d; }); res.on('end', function() { context.succeed(body); }); res.on('error', function(e) { context.fail("got error: " + e.message); }); }); }
using module such request
https://www.npmjs.com/package/request make don't have manage events , code go had before.
Comments
Post a Comment