aws / aws/aws-sam-cli

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

Open
#6,569 7 comments 0 reactions 0 assignees View on GitHub
area/local/invoke stage/bug-repro
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### 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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.