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

aws login
aws certification
aws tutorial
aws console
aws cloud
aws training
aws educate
aws vs azure

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:

|- serverless.yml
|- webpack.config.js
|- package.json
|- src 
  \ - file1.js
  | - file2.js

Extract from serverless.yml

functions:
  function1:
    handler: src/file1.f1
  function2:
    handler: src/file2.f2

Extract from webpack.congfig.js

module.exports = {
  entry: {
    file1: './src/file1.js',
    file2: './src/file2.js',
  },
  target: 'node',
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },
  module: {
    loaders: [
      {
        test: /\.json$/,
        loaders: ['json-loader'],
      },
    ],
  },
};

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

{
  "errorMessage": "Cannot find module '/var/task/src/file1'",
  "errorType": "Error",
  "stackTrace": [
    "Function.Module._load (module.js:276:25)",
    "Module.require (module.js:353:17)",
    "require (internal/module.js:12:17)"
  ]
}

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)

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

Understanding database options for your serverless web applications, AWS Cloud Practitioner Essentials (Second Edition). CurriculumFundamental6 hours. The fundamental-level course is intended for individuals who seek an� The American Welding Society (AWS) was founded in 1919, as a nonprofit organization with a global mission to advance the science, technology and application of welding and allied joining and cutting processes, including brazing, soldering and thermal spraying.

Check the node version

node --version

Run

serverless plugin install --name serverless-webpack

This month in AWS Machine Learning: July 2020 edition, AWS (Amazon Web Services) is a comprehensive, evolving cloud computing platform provided by Amazon that includes a mixture of infrastructure as a service � The AWS Management Console brings the unmatched breadth and depth of AWS right to your computer or mobile phone with a secure, easy-to-access, web-based portal. Discover new services, manage your entire account, build new applications, and learn how to do even more with AWS.

One possible solution to the error is to remove the src/ from the handler of the function in serverless.yml file.

This approach has the side effect that when automatically creating tests with serverless-mocha-plugin the src/ is no longer considered and it must be added manually in const mod = require('../src/user.js');.

There may be other side effects, absence of evidence is not evidence of absence! :)

So, I'm still looking for a solution without side effects.

New – Using Amazon GuardDuty to Protect Your S3 Buckets, There are lots of stories about the formation of AWS, but this much we know: 10 years ago, Amazon Web Services, the cloud Infrastructure as a� Amazon Web Services (AWS) is a subsidiary of Amazon that provides on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. In aggregate, these cloud computing web services provide a set of primitive abstract technical infrastructure and distributed computing building blocks and

AWS Community Builders | Worldwide Cloud Community, Understanding incorrect ML model predictions can be tricky. Learn how to use Amazon SageMaker to capture incorrect model predictions & obtain visual explanations. go.aws/2XnzyFf AWS offers nine different certification categories from inspectors, supervisors and educators to radiographic interpreters, welding engineers and fabricators. The 2020 edition for D1.1 is here! If you are testing to D1.1 between the dates of July 4th, 2020 and December 31st, 2020, you can use either edition (2015 or 2020) of the D1.1 codebook.

Announcing the New AWS Community Builders Program!, 📊 Thank you to our customers for recognizing that public cloud isn't about checking boxes. It's about enabling builders around the world to redefine the future of business. go.aws/30oYgGV Amazon Web Services (AWS) is a comprehensive, evolving cloud computing platform provided by Amazon. It provides a mix of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings.

Amazon Fraud Detector is now Generally Available, A well-designed serverless app can be easily modified to deliver new feature requests while maintaining high availability. @jbesw shows you how to model business logic in serverless architectures, handle state across invocations & manage complex workflows. go.aws/3i3J9ss AWS Pricing Calculator lets you explore AWS services, and create an estimate for the cost of your use cases on AWS.

Comments
  • By reading the links things are getting more clear. I've solved my blocking situation by removing the src/ of handler in serverless.yml file.