Announcements
The Google Cloud Community will be in read-only from July 16 - July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

node.js api proxy error

Not applicable

All,

I am trying to invoke a simple Lambda function from my node.js app which is deployed as a Proxy with all the node dependencies installed.

However, when I try out the app in Apigee I get an error (pasted below). The error seems to come from the require('proxy-agent') node module. The same invocation works fine when called from my local machine. Any ideas what could be wrong? Here is the node.js app code as well -

var express = require('express');

var bodyParser = require('body-parser');

var app = express();

var AWS = require('aws-sdk');

var proxy = require('proxy-agent');


AWS.config.accessKeyId=‘xxxxx’;

AWS.config.secretAccessKey=‘xxxxx’;

AWS.config.region = 'us-east-1';

AWS.config.update({

  httpOptions: { agent: proxy('http://<proxy>:<port>’) },

  httpsOptions: { agent: proxy('http://<proxy>:<port>') }

});


var lambda = new AWS.Lambda();

app.use(bodyParser.json());

app.use(bodyParser.urlencoded({

    extended: true

}));

app.disable('etag');


app.get('/', function(req, res) {

    var params = {

   FunctionName: 'apigeeLambdaTest',

   InvocationType : 'RequestResponse',

   Payload: JSON.stringify(

     {

       "body" : {

          "key":req.body.key

     }

    })};

lambda.invoke(params, function(err, data) {

  console.log("In lambda invoke...");

   if (err)

     {

      res.status(500);

      res.set('Content-Type', 'application/json');

      res.send(err);

     }

   else

    {

      res.status(200);

      res.set('Content-Type', 'application/json');

      res.send(data.Payload);

    }

  });

    

});  




app.listen(9000, function() {

    console.log('Node HTTP server is listening');

});



Error:

{"fault":{"faultstring":"Script node executed prematurely: illegal character\nillegal character\n    at module.js:439\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at \/organization\/environment\/api\/node_modules\/pac-proxy-agent\/node_modules\/socks-proxy-agent\/index.js:8\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at \/organization\/environment\/api\/node_modules\/pac-proxy-agent\/index.js:32\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at \/organization\/environment\/api\/node_modules\/proxy-agent\/index.js:14\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:364\n    at require (module.js:380)\n    at \/organization\/environment\/api\/lambda_test.js:5\n    at module.js:456\n    at module.js:474\n    at module.js:356\n    at module.js:312\n    at module.js:497\n    at startup (trireme.js:142)\n    at trireme.js:923\n","detail":{"errorcode":"scripts.node.runtime.ScriptExitedError"}}}	
1 13 4,136
13 REPLIES 13