0

Currently my barebones function works locally, and returns an authtoken. When I zip the contents of my folder (not the folder itself, an earlier gotcha) and upload/test on Lambda, I get an error "Cannot find module 'bl'", which seems to be coming from

/var/task/node_modules/googleapis/node_modules/google-auth-library/node_modules/request/request.js:9:10.

The bl module is there, I've tried reinstalling just bl and also the whole googleapis module several times. I've tried removing references to bl but none worked. The request module that includes bl is itself included multiple times, so maybe I try referencing bl in a different location. It just doesn't make sense to me that it would work locally, including the module, and not work on lambda.

I have written several Lambda functions but this is the first one I've had to use libraries and upload the zip instead of writing inline, so maybe there is something else I've missed.

Any help would be greatly appreciated.

var https = require('https');
var google = require('googleapis');
var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB(); 

var key = { ... }; 

function requestToken() {
    var scope = 'https://www.googleapis.com/auth/calendar';
    var jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, scope, null);
    jwtClient.authorize(function(err, tokens) {
        if (err) {
          console.log(err);
          return;
        }
        else {
          console.log('token: ' + JSON.stringify(tokens)); // works as intended locally
        }

    });
}

requestToken();
user5347553
  • 79
  • 1
  • 1
  • 6

1 Answers1

1

I just had this same error and what worked for me was reinstalling npm from nodejs.org

skube
  • 5,867
  • 9
  • 53
  • 77