Expose a handler function to Lambda from a Docker Image

Viewed 1036

I'm trying to build a hello world example of a docker image powering a lambda function.

My docker image houses a NPM project that looks like this:

project
│   app.js
|   Dockerfile
|   package.json
|   package-lock.json

The code inside app.js is:

// app.js
module.exports.lambdaHandler = async (event, context) => {
  console.log('Code Running Inside Handler Function');
  console.log(event);
  console.log(context);
  return "Hello World.";
}

I dockerize my app with this CMD layer in my docker file:

CMD [ "app.lambdaHandler" ]

I upload the docker image to AWS and try to run it as a lambda function. However I get the follow runtime error:

Cannot find module '/project/app.lambdaHandler'

How am I supposed to expose 'lambdaHandler' to aws?

Edit to include my docker file:

FROM node:16

COPY app.js ./

CMD [ "app.lambdaHandler" ]
1 Answers
Related