Ben
Ben

Reputation: 81

AWS-SDK in nodejs Lambda function cannot find endpoint-cache module

I've been refactoring some of our AWS lambda functions and with this most recent version I am getting the following error:

"Payload": "{\"errorMessage\":\"Cannot find module '../vendor/endpoint-cache'\",\"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/node_modules/aws-sdk/lib/core.js:76:18)\",\"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)\"]}"

This module is within the vendor folder of the aws-sdk node module. I checked the deployment artifacts to make sure that the folder exists and I've tried downgrading to the older version of the aws-sdk that was being used before.

Dependencies in package.json:

"dependencies": {
    "aws-sdk": "^2.59.0",
    "moment": "^2.22.2",
    "underscore": "^1.8.3"
  },

The build server runs npm-install and then

$path = Get-Location
$thisProject = "$($path)\pathToProject\*"

Compress-Archive -Path $thisProject -DestinationPath thisProject.zip

Been stuck on this for a while so any help is greatly appreciated.

Upvotes: 7

Views: 2939

Answers (4)

Dmitrii Lobanov
Dmitrii Lobanov

Reputation: 4977

I actually encountered the same problem. And in my case the reason was in the Compress-Archive function, run on Windows. If I pack lambda with Compress-Archive, then Lambda call fails with the error in question above. But if I unpack .zip and pack with regular Windows "send to compressed directory" - everything works fine. I've found some similar issue in PowerShell github space, which made me think this is a common problem.

The problem was fixed in one of the latest releases of PowerShell Core (not sure about classic PowerShell). I'm not sure about the exact release which fixes this problem, but it was there in v.6.1, and in v.6.2.2 it's gone.

Upvotes: 2

Eric Johnson
Eric Johnson

Reputation: 328

The recommended approach to specifying the SDK you want in a Lambda function is to create a lambda layer with your desired version. See here: https://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/

Upvotes: 0

Joshua
Joshua

Reputation: 61

I had this issue yesterday, I solved it by removing the aws-sdk in the package.json & deleting + reinstalling my node_modules folder. Hope this solves your problem.

I think the aws-sdk is already included by default.

Upvotes: 3

HeWhoFreeks
HeWhoFreeks

Reputation: 330

I ran into this issue a few months back. Turns out I needed to make sure the package lock file was included in the project and had the aws-sdk version set

Upvotes: 4

Related Questions