aws + serverless + webpack => cannot find module xxx in prod

Question:

I want to create a package to deploy on AWS using serverless and webpack.

In serverless.yml I want to declare all the resources (mainly DynamoDb tables) and the functions. I want to use external node.js libraries.

The folder structure is:

Extract from serverless.yml

Extract from webpack.congfig.js

When doing a serverless deploy everything is ok, but when testing the lambda I get an error:

Can you tell me what am I doing wrong?

Given that I am a newbie with serverless, can you suggest me some “better practice” for the code and development organisation? (serverless and nodejs are imposed, webpack and everything else is not)

Answer:

I would recommend using the serverless-webpack plugin. It’s hard to tell without seeing the entire serverless.yml file, but I would assume that serverless is trying to deploy the functions listed under functions:, which in your case are written in a syntax not understood by the Node.js 4.3 runtime on AWS lambda.

A good walk through on how to set up a project using the serverless-webpack plugin has been detailed by Serverless Stack:

  1. Setup the Serverless Framework
  2. Add Support for ES6 JavaScript

Leave a Reply