question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoking sam local invoke returns an Unable to import module 'index': Error

See original GitHub issue

I’m trying to play with the Hello-world example located in the samples of the repository. However upon invoking sam local invoke "HelloWorld" -e event.json inside the directory where the index, template.yml and is located.

it automatically returns the ff:

START RequestId: e50a858c-69d8-16fc-02d3-70199542bc48 Version: $LATEST Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) END RequestId: e50a858c-69d8-16fc-02d3-70199542bc48 REPORT RequestId: e50a858c-69d8-16fc-02d3-70199542bc48 Duration: 31.25 ms Billed Duration: 0 ms Memory Size: 0 M

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:32 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
Stubie17commented, Jan 15, 2018

FWIW I recently started having this issue trying to test a function that was mounting fine previously. I reset docker to factory defaults, and when I next ran sam local was prompted to allow the drive to be shared and had to enter my password, now it’s working. Quite possibly caused by my password having changed since I allowed the drive share on docker.

7reactions
Kivolcommented, Jan 14, 2018

Maybe I’m on the different case but I’ve resolved the similar Unable to import module issue on Windows, I hope sharing my workaround helps.

I’m using the Windows subsystem for Linux but running Docker on Windows and using Docker on Linux by mapping the port. On WSL, /mnt/c/ is mounted to Windows file system by default.

The problem was that this /mnt/c/blahblah paths are not mounted when running a docker container on WSL, checking on this kind of commands: docker run -it -v /var/run/docker.sock:/var/run/docker.sock -v /mnt/c/Documents/current-working-directory:/data alpine

So I re-mounted the C:\ to /c/ on Linux like this comment: https://github.com/Microsoft/WSL/issues/1854#issuecomment-291845122

And I’ve invoked my function like this: sam local invoke --docker-volume-basedir $(pwd -P) "Hello"

And it worked!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS SAM Local and docker-lambda: keep getting Unable to ...
I'm trying to set up SAM Local with a Python lambda function and keep getting frustrated by the module import error in the...
Read more >
Resolve "Unable to import module" errors from Python ... - AWS
I receive an "Unable to import module" error when I try to run my AWS Lambda code in Python. How do I resolve...
Read more >
Dockerized Lambda: Invoking Sam Local Invoke Returns An ...
Dockerized lambda : Invoking sam local invoke returns an Unable to import module 'index': I am using AWS SAM and dockerized the lambdas....
Read more >
How do I resolve the "Unable to import module" error I receive ...
How do I resolve the " Unable to import module " error I receive when I run Lambda code in Python?
Read more >
awslabs/aws-sam-local - Gitter
Pulls code from Github, runs through sam validate and returns if the app passes the build or not.. We can even call sam...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found