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"}}}