Lambda fails after deployment: Runtime.ImportModuleError "errorMessage":"Error: Cannot find module s-<function>`

After successfully deploying my stack using serverless deploy, my lambda functions fail, citing a module import error Runtime.ImportModuleError.

Because I need binaries built specifically for linux, the packaging and deployment takes place inside a docker container, the docker file is as follows:

FROM lambci/lambda:build-nodejs10.x

ENV AWS_DEFAULT_REGION XXXX

ENV SERVERLESS_ACCESS_KEY XXXXXXXXXXXXXXXX

ENV AWS_ACCESS_KEY_ID XXXXXXXXXXXX
ENV AWS_SECRET_ACCESS_KEY XXXXXXXXXXXXXXX

RUN npm install -g serverless

WORKDIR /usr/src/app

COPY . .

RUN rm -rf node_modules

RUN npm install

CMD serverless deploy
The lambda’s stack trace is as follows:

{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 's-fetchUserData'",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module 's-fetchUserData'",
    "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:36:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:776:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)",
    "    at Module.load (internal/modules/cjs/loader.js:653:32)",
    "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
    "    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)",
    "    at startup (internal/bootstrap/node.js:283:19)"
  ]
}

If I download the .zip file from s3 for the deployment, I can see the s_fetchUserData.js file in the root of the project.

Here’s the file tree:

.
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ NOTES.md
β”œβ”€β”€ README.md
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ s_fetchUserData.js
β”œβ”€β”€ s_generateEmail.js
β”œβ”€β”€ s_processGif.js
β”œβ”€β”€ s_processPhoto.js
β”œβ”€β”€ s_processTimelapseVideo.js
β”œβ”€β”€ s_startExecution.js
β”œβ”€β”€ serverless_sdk
β”‚ └── index.js
└── src
β”œβ”€β”€ handlers
β”‚ β”œβ”€β”€ email
β”‚ β”‚ β”œβ”€β”€ handler.js
β”‚ β”‚ └── mira.code-workspace
β”‚ β”œβ”€β”€ image-processing
β”‚ β”‚ β”œβ”€β”€ gif
β”‚ β”‚ β”‚ └── handler.js
β”‚ β”‚ └── photo
β”‚ β”‚ └── handler.js
β”‚ β”œβ”€β”€ start
β”‚ β”‚ └── handler.js
β”‚ β”œβ”€β”€ test
β”‚ β”‚ └── handler.js
β”‚ β”œβ”€β”€ timelapse
β”‚ β”‚ └── handler.js
β”‚ β”œβ”€β”€ upload
β”‚ β”‚ └── handler.js
β”‚ β”œβ”€β”€ user
β”‚ β”‚ └── handler.js
β”‚ └── video
β”‚ └── timelapse
β”‚ └── handler.js
β”œβ”€β”€ templates
β”‚ └── email
β”‚ └── content.pug
β”œβ”€β”€ test
β”‚ β”œβ”€β”€ email.json
β”‚ β”œβ”€β”€ index.html
β”‚ β”œβ”€β”€ locationData.json
β”‚ β”œβ”€β”€ processImage.json
β”‚ β”œβ”€β”€ pugRenderer.js
β”‚ β”œβ”€β”€ timelapse.json
β”‚ β”œβ”€β”€ timelapseVideo.json
β”‚ β”œβ”€β”€ user.json
β”‚ └── views
β”‚ β”œβ”€β”€ email-bg.svg
β”‚ └── index.pug
└── utils
└── index.js

19 directories, 35 files

Only just started with this stuff myself but in the error message it’s β€˜s-fetchUserData’ and in the tree β€˜s_fetchUserData.js’ so maybe the -_ needs correcting somewhere?

1 Like