502016 (2) [Avatar] Offline
I am trying to invoke lamda function from the web application - as mentioned in 5.3.4 but I get the following error:

  "errorMessage": "Cannot find module 'ecdsa-sig-formatter'",
  "errorType": "Error",
  "stackTrace": [
    "require (internal/module.js:12:17)",
    "Object.<anonymous> (/var/task/node_modules/jwa/index.js:5:19)",
    "Module._compile (module.js:409:26)",
    "Object.Module._extensions..js (module.js:416:10)",
    "Module.load (module.js:343:32)",
    "Function.Module._load (module.js:300:12)",
    "Module.require (module.js:353:17)"

I see the module ecdsa-sig-formatter in node_modules directory in the zip uploaded to Lambda. What could be wrong?

index.js is below:

"use strict";

var jwt = require("jsonwebtoken");
var request = require("request");

exports.handler = function(event, context, callback) {
  if (!event.authToken) {
    callback("Could not find authToken");
  var token = event.authToken.split(" ")[1];
  var secretBuffer = new Buffer(process.env.AUTH0_SECRET);
  jwt.verify(token, secretBuffer, function(err, decoded) {
    if (err) {
      console.log("Failed jwt verification", err, "auth: ", event.authToken);
      callback("Authorization Failed");
    } else {
      var body = { id_token: token };

    var options = {
      url: "https://" + process.env.DOMAIN + "/tokeninfo",
      method: "POST",
      json: true,
      body: body

    request(options, function(error, response, body) {
      if (!error && response.statusCode === 200) {
        callback(null, body);
      } else {
502016 (2) [Avatar] Offline
Fixed! It looks like package.json file is needed in this case under \node_modules\ecdsa-sig-formatter. This is how my predepoly script looked like when I was getting the error:

"7z a Lambda-Deployment.zip * -r -x!*.zip -x!*.json -x!*.log"

After deleting the exclude from this script my code started working. Updated predeploy script:

"7z a Lambda-Deployment.zip * -r -x!*.zip -x!*.log"

I didn't have to do this for previous Lambda function I created using the book examples. The one thing different I noticed in the module throwing the error was that it didn't have any js file in the root folder but inside src folder (\ecdsa-sig-formatter\src). It looks like Node needs to have package.json or js file in the root module to work. Probably a good idea not exclude json files?

similar issue: https://forums.aws.amazon.com/thread.jspa?threadID=181471