question

sanuSky avatar image
sanuSky asked

I cant add 3rd party node modules For alexa lambda function

I am using tableau-api in node module of lamda function. But unfortunately this module is not able to import in my lambda function. module is available in NPM site and i followed the documentation properly, but nothing could help me.

for example :

'use strict';
const Alexa = require("alexa-sdk");
var tab = require("tableau-api");

exports.handler = function(event, context, callback) {
    const alexa = Alexa.handler(event, context);
    alexa.registerHandlers(handlers);
    alexa.execute();
};

const handlers = {
    'LaunchRequest': function() {
        this.emit('SayHello');
    },
    'HelloWorldIntent': function() {
        this.emit('SayHello');
    }
};
  • When i test this code error is showing.
"errorMessage": "Cannot find module 'tableau-api'",
  "errorType": "Error",
  "stackTrace": [
    "Function.Module._load (module.js:474:25)",
    "Module.require (module.js:596:17)",
    "require (internal/module.js:11:18)",
    "Object.<anonymous> (/var/task/index.js:3:11)",
    "Module._compile (module.js:652:30)",
    "Object.Module._extensions..js (module.js:663:10)",
    "Module.load (module.js:565:32)",
    "tryModuleLoad (module.js:505:12)",
    "Function.Module._load (module.js:497:3)"
alexa skills kitlambdaapinode_js
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Andy Whitworth avatar image
Andy Whitworth answered

You need to create a zip file containing your index.js file and a node_modules directory containing all of the npm packages used by your skill (including tableau-api).

I create a directory on my home PC with all this in (and test it there too) and then zip up the skill directory and upload to AWS lambda.

Note: The zip file must have index.js at the top level (root) not in a subdir! So don't zip up the directory containing index.js and node_modules but zip up the contents of the directory.

So zip file looks like:

index.js
node_modules/

And NOT

projectDir/
	index.js
	node_modules

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.