aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Sam local invoke and sam local start-api have mounting code issues #1126

Closed ms-clovis closed 5 years ago

ms-clovis commented 5 years ago

Description

When I use sam local invoke or start-api there is an error 👍 "errorMessage":"Cannot find module '/var/task/app'","errorType":"Error","stackTrace":["Function.Module._load (module.js:474:25)","Module.require (module.js:596:17)","require (internal/module.js:11:18)"]}

Steps to reproduce

  1. On windows 10 pro (Hyper-V issues, uninstalled)
  2. Install Docker Toolbox version v18.09.3
  3. Docker and Docker-machine version info: docker-machine version 0.16.1, build cce350d7 Docker version 18.09.3, build 774a1f4eee
  4. Docker-machine create a server (docker-machine create box)(boot2Docker , busybox)
  5. docker-machine env box SET DOCKER_TLS_VERIFY=1 SET DOCKER_HOST=tcp://192.168.99.100:2376 SET DOCKER_CERT_PATH=C:\Users\mike.MOYACREW.000.docker\machine\machines\box SET DOCKER_MACHINE_NAME=box SET COMPOSE_CONVERT_WINDOWS_PATHS=true REM Run this command to configure your shell: REM @FOR /f "tokens=*" %i IN ('docker-machine env box') DO @%i
  6. While I initially used lambda java code (same error) and a template I then ran: sam init
  7. cd sam-app
  8. Both sam local start-api and sam local invoke HelloWorldFunction --event event.json

(same error)

{"errorMessage":"Cannot find module '/var/task/app'","errorType":"Error","stackTrace":["Function.Module._load (module.js:474:25)","Module.require (module.js:596:17)","require (internal/module.js:11:18)"]}

Observed result

2019-04-15 15:08:02 Using SAM Template at c:\Intellij_Projs\sam-app.aws-sam\build\template.yaml 2019-04-15 15:08:02 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane 2019-04-15 15:08:02 Changing event name from before-call.apigateway to before-call.api-gateway 2019-04-15 15:08:02 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict 2019-04-15 15:08:02 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration 2019-04-15 15:08:02 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53 2019-04-15 15:08:02 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search 2019-04-15 15:08:02 Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section 2019-04-15 15:08:02 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask 2019-04-15 15:08:02 Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section 2019-04-15 15:08:02 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search 2019-04-15 15:08:02 Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section 2019-04-15 15:08:02 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane 2019-04-15 15:08:02 Changing event name from before-call.apigateway to before-call.api-gateway 2019-04-15 15:08:02 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict 2019-04-15 15:08:02 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration 2019-04-15 15:08:02 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53 2019-04-15 15:08:02 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search 2019-04-15 15:08:02 Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section 2019-04-15 15:08:02 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask 2019-04-15 15:08:02 Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section 2019-04-15 15:08:02 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search 2019-04-15 15:08:02 Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section 2019-04-15 15:08:02 local invoke command is called 2019-04-15 15:08:03 No Parameters detected in the template 2019-04-15 15:08:03 2 resources found in the template 2019-04-15 15:08:03 Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction' 2019-04-15 15:08:03 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:03 No config file found 2019-04-15 15:08:03 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:03 No config file found 2019-04-15 15:08:03 Starting new HTTPS connection (1): 192.168.99.100:2376 2019-04-15 15:08:03 https://192.168.99.100:2376 "GET /v1.35/_ping HTTP/1.1" 200 2 2019-04-15 15:08:03 Looking for credentials via: env 2019-04-15 15:08:03 Looking for credentials via: assume-role 2019-04-15 15:08:03 Looking for credentials via: shared-credentials-file 2019-04-15 15:08:03 Found credentials in shared credentials file: ~/.aws/credentials 2019-04-15 15:08:03 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\endpoints.json 2019-04-15 15:08:03 Event choose-service-name: calling handler <function handle_service_name_alias at 0x0000019ED7BD6048> 2019-04-15 15:08:04 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\lambda\2015-03-31\service-2.json 2019-04-15 15:08:04 Event creating-client-class.lambda: calling handler <function add_generate_presigned_url at 0x0000019ED7B79EA0> 2019-04-15 15:08:04 The s3 config key is not a dictionary type, ignoring its value of: None 2019-04-15 15:08:04 Setting lambda timeout as (60, 60) 2019-04-15 15:08:04 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data_retry.json 2019-04-15 15:08:04 Registering retry handlers for service: lambda 2019-04-15 15:08:04 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:04 No config file found 2019-04-15 15:08:04 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:04 No config file found 2019-04-15 15:08:04 Found one Lambda function with name 'HelloWorldFunction' 2019-04-15 15:08:04 Invoking app.lambdaHandler (nodejs8.10) 2019-04-15 15:08:04 No environment variables found for function 'HelloWorldFunction' 2019-04-15 15:08:04 Environment variables overrides data is standard format 2019-04-15 15:08:04 Loading AWS credentials from session with profile 'default' 2019-04-15 15:08:04 Resolving code path. Cwd=c:\Intellij_Projs\sam-app.aws-sam\build, CodeUri=HelloWorldFunction 2019-04-15 15:08:04 Resolved absolute path to code is c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction 2019-04-15 15:08:04 Code c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction is not a zip/jar file 2019-04-15 15:08:04 Skipping building an image since no layers were defined 2019-04-15 15:08:04 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:04 No config file found 2019-04-15 15:08:04 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:04 No config file found 2019-04-15 15:08:04 https://192.168.99.100:2376 "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None 2019-04-15 15:08:04 Looking for auth config 2019-04-15 15:08:04 No auth config in memory - loading from filesystem 2019-04-15 15:08:04 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-15 15:08:04 No config file found 2019-04-15 15:08:04 Looking for auth entry for 'docker.io' 2019-04-15 15:08:04 No entry found 2019-04-15 15:08:04 No auth config found 2019-04-15 15:08:04 https://192.168.99.100:2376 "POST /v1.35/images/create?tag=nodejs8.10&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:nodejs8.10 Docker container image...... 2019-04-15 15:08:04 Mounting c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction as /var/task:ro inside runtime container 2019-04-15 15:08:04 Starting new HTTPS connection (1): 192.168.99.100:2376 2019-04-15 15:08:04 https://192.168.99.100:2376 "POST /v1.35/containers/create HTTP/1.1" 201 90 2019-04-15 15:08:05 https://192.168.99.100:2376 "GET /v1.35/containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79/json HTTP/1.1" 200 None 2019-04-15 15:08:05 https://192.168.99.100:2376 "GET /v1.35/containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79/json HTTP/1.1" 200 None 2019-04-15 15:08:05 https://192.168.99.100:2376 "POST /v1.35/containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79/start HTTP/1.1" 204 0 2019-04-15 15:08:05 Starting a timer for 3 seconds for function 'HelloWorldFunction' 2019-04-15 15:08:05 https://192.168.99.100:2376 "GET /v1.35/containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79/json HTTP/1.1" 200 None 2019-04-15 15:08:05 https://192.168.99.100:2376 "POST /containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0 START RequestId: 98151084-4199-1dd5-c832-9cf8281429da Version: $LATEST Unable to import module 'app': Error  at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) END RequestId: 98151084-4199-1dd5-c832-9cf8281429da REPORT RequestId: 98151084-4199-1dd5-c832-9cf8281429da Duration: 18.22 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 30 MB  2019-04-15 15:08:06 Starting new HTTPS connection (2): 192.168.99.100:2376 2019-04-15 15:08:06 https://192.168.99.100:2376 "GET /v1.35/containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79/json HTTP/1.1" 200 None 2019-04-15 15:08:06 https://192.168.99.100:2376 "DELETE /v1.35/containers/e58539935947dc482a092e9a1fcb6fc0351a12813d2b34162ae117324e3cbc79?v=False&link=False&force=True HTTP/1.1" 204 0

{"errorMessage":"Cannot find module '/var/task/app'","errorType":"Error","stackTrace":["Function.Module._load (module.js:474:25)","Module.require (module.js:596:17)","require (internal/module.js:11:18)"]}

Expected result

Hello World!

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

  1. OS: Windows 10 Pro -- hyper-v not installed user is domain administrator and command prompt is elevated.
  2. sam --version SAM CLI, version 0.14.2

Thanks in advance!

ms-clovis commented 5 years ago

Do I need to mount a volume using docker-machine... If so what (just a guess will do) Docker-Machine image "box" has two mounts c:\Users and c:\ still no joy

sriram-mv commented 5 years ago

This is most likely a docker issue, see if the location you are trying to mount is shared within docker settings.

I just tried on a windows machine and invoke worked.

ms-clovis commented 5 years ago

TheSriram, thank you for your help, Could you please advise as to the settings/commands that need to be used. The error is:

Fetching lambci/lambda:nodejs8.10 Docker container image...... 2019-04-15 19:15:06 Mounting c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction as /var/task:ro inside runtime container START RequestId: 238b5191-970d-1e7c-1ef1-ea9463fd1ce2 Version: $LATEST Unable to import module 'app': Error

And this is using docker-machine and virtual box...

ms-clovis commented 5 years ago

Sriram,

If you tried this on a windows machine using docker-machine and virtual box, Could you please advise as how you accomplished it?

My debug info prior to error is

Mounting c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction as /var/task:ro inside runtime container

also in the template: CodeUri: hello-world/ which seems correct.

Thanks in advance,

ms-clovis commented 5 years ago

bump, can someone weigh in? Keeping the issue open.

ms-clovis commented 5 years ago

In addition the mapped drives (shared folders in virtual box) are /c/ to c:\ and c/Users to c:\Users

jfuss commented 5 years ago

@ms-clovis By chance is this happening on the first time you sam build? If so, can you try upgrading to 0.15.0? I have a hunch this is happening due to #1110 given the path is missing a \ between sam-app and .aws-sam

ms-clovis commented 5 years ago

jfuss, it could be. I am using sam version 0.14.2 (current msi installer, as pip3 installed even earlier one). I tried workaround by mapping to .aws-sam folder in question, but no joy. Any ideas?

Looking at the output 👍

sam local invoke -t .aws-sam\build\template.yaml -e event.json --debug 2019-04-17 12:12:32 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane 2019-04-17 12:12:32 Changing event name from before-call.apigateway to before-call.api-gateway 2019-04-17 12:12:32 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict 2019-04-17 12:12:32 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration 2019-04-17 12:12:32 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53 2019-04-17 12:12:32 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search 2019-04-17 12:12:32 Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section 2019-04-17 12:12:32 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask 2019-04-17 12:12:32 Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section 2019-04-17 12:12:32 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search 2019-04-17 12:12:32 Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section 2019-04-17 12:12:32 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane 2019-04-17 12:12:32 Changing event name from before-call.apigateway to before-call.api-gateway 2019-04-17 12:12:32 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict 2019-04-17 12:12:32 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration 2019-04-17 12:12:32 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53 2019-04-17 12:12:32 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search 2019-04-17 12:12:32 Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section 2019-04-17 12:12:32 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask 2019-04-17 12:12:32 Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section 2019-04-17 12:12:32 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search 2019-04-17 12:12:32 Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section 2019-04-17 12:12:32 local invoke command is called 2019-04-17 12:12:32 No Parameters detected in the template 2019-04-17 12:12:32 2 resources found in the template 2019-04-17 12:12:32 Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction' 2019-04-17 12:12:32 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:32 No config file found 2019-04-17 12:12:32 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:32 No config file found 2019-04-17 12:12:32 Starting new HTTPS connection (1): 192.168.99.100:2376 2019-04-17 12:12:33 https://192.168.99.100:2376 "GET /v1.35/_ping HTTP/1.1" 200 2 2019-04-17 12:12:33 Looking for credentials via: env 2019-04-17 12:12:33 Looking for credentials via: assume-role 2019-04-17 12:12:33 Looking for credentials via: shared-credentials-file 2019-04-17 12:12:33 Found credentials in shared credentials file: ~/.aws/credentials 2019-04-17 12:12:33 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\endpoints.json 2019-04-17 12:12:33 Event choose-service-name: calling handler <function handle_service_name_alias at 0x000001F0E3CD6048> 2019-04-17 12:12:33 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\lambda\2015-03-31\service-2.json 2019-04-17 12:12:33 Event creating-client-class.lambda: calling handler <function add_generate_presigned_url at 0x000001F0E3C79EA0> 2019-04-17 12:12:33 The s3 config key is not a dictionary type, ignoring its value of: None 2019-04-17 12:12:33 Setting lambda timeout as (60, 60) 2019-04-17 12:12:33 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data_retry.json 2019-04-17 12:12:33 Registering retry handlers for service: lambda 2019-04-17 12:12:33 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:33 No config file found 2019-04-17 12:12:33 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:33 No config file found 2019-04-17 12:12:33 Found one Lambda function with name 'HelloWorldFunction' 2019-04-17 12:12:33 Invoking app.lambdaHandler (nodejs8.10) 2019-04-17 12:12:33 No environment variables found for function 'HelloWorldFunction' 2019-04-17 12:12:33 Environment variables overrides data is standard format 2019-04-17 12:12:33 Loading AWS credentials from session with profile 'default' 2019-04-17 12:12:33 Resolving code path. Cwd=c:\Intellij_Projs\sam-app.aws-sam\build, CodeUri=HelloWorldFunction 2019-04-17 12:12:33 Resolved absolute path to code is c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction 2019-04-17 12:12:33 Code c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction is not a zip/jar file 2019-04-17 12:12:33 Skipping building an image since no layers were defined 2019-04-17 12:12:33 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:33 No config file found 2019-04-17 12:12:33 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:33 No config file found 2019-04-17 12:12:33 https://192.168.99.100:2376 "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None 2019-04-17 12:12:33 Looking for auth config 2019-04-17 12:12:33 No auth config in memory - loading from filesystem 2019-04-17 12:12:33 Trying paths: ['C:\Users\mike.MOYACREW.000\.docker\config.json', 'C:\Users\mike.MOYACREW.000\.dockercfg'] 2019-04-17 12:12:33 No config file found 2019-04-17 12:12:33 Looking for auth entry for 'docker.io' 2019-04-17 12:12:33 No entry found 2019-04-17 12:12:33 No auth config found 2019-04-17 12:12:34 https://192.168.99.100:2376 "POST /v1.35/images/create?tag=nodejs8.10&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:nodejs8.10 Docker container image...... 2019-04-17 12:12:34 Mounting c:\Intellij_Projs\sam-app.aws-sam\build\HelloWorldFunction as /var/task:ro inside runtime container 2019-04-17 12:12:34 Starting new HTTPS connection (1): 192.168.99.100:2376 2019-04-17 12:12:34 https://192.168.99.100:2376 "POST /v1.35/containers/create HTTP/1.1" 201 90 2019-04-17 12:12:34 https://192.168.99.100:2376 "GET /v1.35/containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d/json HTTP/1.1" 200 None 2019-04-17 12:12:34 https://192.168.99.100:2376 "GET /v1.35/containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d/json HTTP/1.1" 200 None 2019-04-17 12:12:35 https://192.168.99.100:2376 "POST /v1.35/containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d/start HTTP/1.1" 204 0 2019-04-17 12:12:35 Starting a timer for 3 seconds for function 'HelloWorldFunction' 2019-04-17 12:12:35 https://192.168.99.100:2376 "GET /v1.35/containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d/json HTTP/1.1" 200 None 2019-04-17 12:12:35 https://192.168.99.100:2376 "POST /containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0 START RequestId: 55897d4f-56fc-134b-1d57-590ba06550d9 Version: $LATEST Unable to import module 'app': Error  at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) END RequestId: 55897d4f-56fc-134b-1d57-590ba06550d9 REPORT RequestId: 55897d4f-56fc-134b-1d57-590ba06550d9 Duration: 23.03 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 30 MB  2019-04-17 12:12:35 Starting new HTTPS connection (2): 192.168.99.100:2376 2019-04-17 12:12:35 https://192.168.99.100:2376 "GET /v1.35/containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d/json HTTP/1.1" 200 None 2019-04-17 12:12:35 https://192.168.99.100:2376 "DELETE /v1.35/containers/b60077b8a6c8cb6b11a2146cb34d603e62c7a275b635957332523fb3eea3279d?v=False&link=False&force=True HTTP/1.1" 204 0

{"errorMessage":"Cannot find module '/var/task/app'","errorType":"Error","stackTrace":["Function.Module._load (module.js:474:25)","Module.require (module.js:596:17)","require (internal/module.js:11:18)"]}

Leads me to believe that in this case (docker-machine), the docker daemon is running on the VM "box" that docker-machine started and that the aws container running on box is the one having issues.

ms-clovis commented 5 years ago

at least that is my assumption on what is going on

as a followup, I invoked using start-lambda and invoked in another prompt using

aws lambda invoke --function-name "HelloWorldFunction" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt

with the same issues. I then ssh into "box" moved the files to /var/task and still the same issue.

Hope that helps someone help me.

Thanks in advance.

ms-clovis commented 5 years ago

Bump, hope someone can help

sriram-mv commented 5 years ago

Can you try moving your project out to your own user directory? instead of C:\Intellij_projs

ms-clovis commented 5 years ago

Sriram, thanks for still helping! Sorry though same error!

ms-clovis commented 5 years ago

Can you try moving your project out to your own user directory? instead of C:\Intellij_projs

Same error

ms-clovis commented 5 years ago

bump

webartoli commented 5 years ago

I have the same issue: following the official Quick Start

Here below there are the simple commands I tried on different platform:

$ sam init --runtime python3.6 
$ cd sam-app
$ cat event.json | sam local invoke HelloWorldFunction

Results:

A failed run output appears as follow:

> $ cat event.json | sam local invoke HelloWorldFunction
2019-04-23 18:41:08 Reading invoke payload from stdin (you can also pass it from file with --event)
2019-04-23 18:41:08 Found credentials in shared credentials file: ~/.aws/credentials
2019-04-23 18:41:08 Invoking app.lambda_handler (python3.6)

Fetching lambci/lambda:python3.6 Docker container image......
2019-04-23 18:41:11 Mounting /mnt/d/_work/sam-app/hello_world as /var/task:ro,delegated inside runtime container
START RequestId: b2436662-4844-4890-88a1-53c83b70e98f Version: $LATEST
Unable to import module 'app': No module named 'app'
END RequestId: b2436662-4844-4890-88a1-53c83b70e98f
REPORT RequestId: b2436662-4844-4890-88a1-53c83b70e98f Duration: 1 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 19 MB

{"errorMessage": "Unable to import module 'app'"}
jfuss commented 5 years ago

@webartoli See https://github.com/awslabs/aws-sam-cli/issues/1145#issuecomment-485811241

webartoli commented 5 years ago

@jfuss Already seen, in particular on that guide I have:

so ls /mnt/c and ls /c give me the same output.

Plain windows (without WSL) fail as well with the same behaviour.

jfuss commented 5 years ago

This still applies:

"This smells like a docker sharing issue. SAM CLI does a bind mount and if the share settings are not enabled for where you are working, then docker swallows the error and pretends everything is fine. On Windows, we have seen needing to toggle the share settings (on drives/directories) for Docker for Windows to pick up the settings. Both are really unclear and an issue with Docker."

ms-clovis commented 5 years ago

I solved the issue by nuking the computer, and reinstalling windows, everything worked correctly (am using docker for windows and hyper-v now instead of docker toolbox and virtualbox). Thanks for all the help. I personally believe that toolbox is the problem.

jkhaui commented 5 years ago

To be honest, it's a bit ridiculous that such a common issue (at least that's what I gather after spending a whole day searching for an answer) has absolutely no helpful solutions/guidance anywhere. It shouldn't matter if the issue is with sam or docker or wherever; if one is following the instructions provided in a "hello world" tutorial, one should expect it to work. Sorry if my tone is overly harsh. I'm just frustrated at wasting an entire day and am giving up on setting up a local lambda dev environment. Hope someone finally gets to the bottom of this.

PorterTruax commented 5 years ago

Have you tried toggling back and forth the 'shared drives in your Docker settings (uncheck, hit apply, check again). I was just dealing with the same issue. Toggling back and forth fixed it:

https://github.com/awslabs/aws-sam-cli/issues/1145#issuecomment-485811241

SSathish89 commented 5 years ago

I am getting error while sam local invoke { "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'app'" } Window 10 home In Virtual tool box i shared the folder virtualshared

BaibhavVishal123 commented 4 years ago

Found a temporary solution for HelloWorldFunction from this https://github.com/aws-samples/aws-serverless-workshops/issues/160 I have windows 10 home, and docker toolbox.

Now somewhere while installing, docker volume mount has been restricted to C:\Users\<username>. Username being the one by which you installed docker.

So, move your project inside this folder.

Also docker needs to be running. If you are using "cmd" , just type docker --version in the same cmd window to do the trick.

Do npm install for axios required for this function, and you are good to go.

CMD: sam local invoke HelloWorldFunction --no-event

O/P:

C:\Users\Administrator\workspace\sam-app>sam local invoke HelloWorldFunction --no-event
2019-12-01 10:57:35 Found credentials in shared credentials file: ~/.aws/credentials
2019-12-01 10:57:36 Invoking app.lambdaHandler (nodejs8.10)

Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-12-01 10:57:40 Mounting C:\Users\Administrator\workspace\sam-app\hello-world as /var/task:ro inside runtime container
START RequestId: 35035697-67d6-1323-4861-a6c1063a1e30 Version: $LATEST
END RequestId: 35035697-67d6-1323-4861-a6c1063a1e30
REPORT RequestId: 35035697-67d6-1323-4861-a6c1063a1e30     Init Duration: 716.80 ms        Duration: 666.14 ms
        Billed Duration: 700 ms Memory Size: 128 MB     Max Memory Used: 40 MB  

{"statusCode":200,"body":"{\"message\":\"hello world\",\"location\":\"49.205.223.103\"}"}