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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -