0

I'm trying to create a simple application following this article, but I cannot get my Node Lambda function to find the dynamodb-geo package.

Here is what I have:

const AWS = require('aws-sdk');
const ddbGeo = require('dynamodb-geo');

exports.handler = async (event, context) => {
  // Rest of the code here
};

And the error Lambda throws is:

START RequestId: 5d40d132-040f-447d-bd76-35c4cec0236a Version: $LATEST 2019-10-05T10:04:24.719Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'dynamodb-geo'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'dynamodb-geo'"," at _loadUserApp (/var/runtime/UserFunction.js:100:13)"," at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","
at Object. (/var/runtime/index.js:45:30)"," at Module._compile (internal/modules/cjs/loader.js:778:30)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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:831:12)","
at startup (internal/bootstrap/node.js:283:19)"]} END RequestId: 5d40d132-040f-447d-bd76-35c4cec0236a REPORT RequestId: 5d40d132-040f-447d-bd76-35c4cec0236a Duration: 1146.75 ms Billed Duration: 1200 ms Memory Size: 512 MB Max Memory Used: 35 MB Unknown application error occurred Runtime.ImportModuleError

Any clue on what could be happening?

javag87
  • 61
  • 6

3 Answers3

1

The only included package on AWS Lambda is the aws-sdk package. Everything else (except standard node packages) needs to be packaged and uploaded with your code.

There are many tools to achieve this:

ElFitz
  • 908
  • 1
  • 8
  • 26
0

Have you installed the package?

Using npm or yarn: npm install --save dynamodb-geo or yarn add dynamodb-geo.

Doc: https://www.npmjs.com/package/dynamodb-geo

Horatiu Jeflea
  • 7,256
  • 6
  • 38
  • 67
  • 1
    Thank you for your sugestion. I'm running this project in a serverless environment. I cannot just install the package. You guided my investigation though, and I found out that actually AWS does not include that package in its runtime, and if I want to use it I need to upload it as part of the code. – javag87 Oct 06 '19 at 18:32
  • 1
    yes, you were missing the packages in your lambda. I suggest using serverless framework for deployment, so you can add dependecies easier https://serverless.com/framework/docs/providers/aws/guide/packaging/ – Horatiu Jeflea Oct 06 '19 at 18:44
0

You can use a Lambda layer in order to easily import external packages:

Doron Goldberg
  • 643
  • 1
  • 9
  • 23