I have created node.js proxy in Apigee using AWS-SDK to connec to AWS Lambda. Below is the node.js code
var AWS = require('aws-sdk'); var apigee = require('apigee-access'); var http = require('http'); var lambda = null; var server = http.createServer(function (request, resp) { if (!lambda) { var accessKeyId = apigee.getVariable(request, 'private.accessKeyId'); var secretAccessKey = apigee.getVariable(request, 'private.secretAccessKey'); var region = apigee.getVariable(request, 'private.region'); AWS.config.update({accessKeyId: accessKeyId, secretAccessKey: secretAccessKey, region: region}); lambda = new AWS.Lambda(); } var requestPayload = apigee.getVariable(request, 'request.content'); var params = { FunctionName: 'get-pingstatus-status', InvocationType: 'RequestResponse', LogType: 'Tail', Payload: requestPayload }; lambda.invoke(params, function (err, data) { if (err) { resp.end('Error: ' + err); } else { resp.end(data.Payload); } }); }); server.listen(process.env.PORT || 9000, function() { console.log('Node HTTP server is listening'); });
Manually added "new script" file of type "node" with name "package.json". Below is the code added in it.
{ "name": "lambda-sample", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "aws-sdk": "^2.148.0" } }
I have added KVM policy to get the AWS login credentials. Below is the code in KVM policy.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Key-Value-Map-Operations-1" mapIdentifier="aws-config"> <DisplayName>Key Value Map Operations-1</DisplayName> <Properties/> <Get assignTo="private.accessKeyId"> <Key> <Parameter>accessKeyId</Parameter> </Key> </Get> <Get assignTo="private.secretAccessKey"> <Key> <Parameter>secretAccessKey</Parameter> </Key> </Get> <Get assignTo="private.region"> <Key> <Parameter>region</Parameter> </Key> </Get> <Scope>environment</Scope> </KeyValueMapOperations>
I have saved and deployed and while testing below error is shown.
{"fault":{"faultstring":"Script node executed prematurely: Error: Cannot find module 'aws-sdk'\nError: Cannot find module 'aws-sdk'\n at module.js:340:0\n at module.js:280:0\n at module.js:364:0\n at require (module.js:380:0)\n at \/organization\/environment\/api\/callLambda.js:1:0\n at module.js:456:0\n at module.js:474:0\n at module.js:356:0\n at module.js:312:0\n at module.js:497:0\n at startup (trireme.js:142:0)\n at trireme.js:923:0\n","detail":{"errorcode":"scripts.node.runtime.ScriptExitedError"}}}
I tried adding attached AWS-SDK zip using Resource API (file upload) see link below. But no luck link says file successfully uploaded and testing still error remains same.
HTTP/1.1 201 CreatedAccess-Control-Allow-Headers:originAccess-Control-Allow-Methods:GETAccess-Control-Allow-Origin:*Access-Control-Max-Age:3628800Connection:keep-aliveContent-Length:47Content-Type:application/jsonDate:Tue, 19 Feb 2019 15:52:08 GMTServer:Apigee LB{ "name": "aws-sdk.zip", "type": "node" }
Please suggest what am missing here.
Hello Folks,
Any inputs please.!!
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |