Skip to content

Bug: sam local invoke "Cannot find module 'index'" (happens when running from docker container only) #6569

Open
@osotnikov

Description

@osotnikov

Description:

When doing a sam build followed by a sam local invoke on a simple hello world lambda (nodejs16) everything works fine on windows but fails on linux (docker container, ubuntu:jammy-20220801).

Steps to reproduce:

Install nodejs 16 (although same observed on 20 as well). Create a small helloWorld.js lambda, create a basic template.yaml, run sam build, run sam local invoke.

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Description: A simple Hello World Serverless project
Resources:
  HelloWorld:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs16.x
      Handler: index.handler
      CodeUri: .
`'use strict';

// A simple hello world Lambda function
exports.handler = (event, context, callback) => {

    console.log('LOG: Name is ' + event.name);
    callback(null, "Hello " + event.name);

}

Observed result:

On windows:

11111

On jammy docker container:

22222

same happens with node 16.13 as well...

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

docker container works on the same folder as windows with parent folder being mounted as volume.

version: "3.9"
services:
  stockmonitor:
    container_name: stockmonitor-infrastructure
    image: stockmonitor_main
    stdin_open: true # docker run -i
    tty: true        # docker run -t
    volumes:
      - ../..:/app
      - /var/run/docker.sock:/var/run/docker.sock
    network_mode: host

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions