Sam local invoke and sam local start-api have mounting code issues
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
- On windows 10 pro (Hyper-V issues, uninstalled)
- Install Docker Toolbox version v18.09.3
- Docker and Docker-machine version info: docker-machine version 0.16.1, build cce350d7 Docker version 18.09.3, build 774a1f4eee
- Docker-machine create a server (docker-machine create box)(boot2Docker , busybox)
- 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
- While I initially used lambda java code (same error) and a template I then ran: sam init
- cd sam-app
- 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 [32mSTART RequestId: 98151084-4199-1dd5-c832-9cf8281429da Version: $LATEST[0m [31mUnable to import module 'app': Error[0m [31m 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)[0m [32mEND RequestId: 98151084-4199-1dd5-c832-9cf8281429da[0m [32mREPORT RequestId: 98151084-4199-1dd5-c832-9cf8281429da Duration: 18.22 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 30 MB [0m 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)
- OS: Windows 10 Pro -- hyper-v not installed user is domain administrator and command prompt is elevated.
- sam --version SAM CLI, version 0.14.2
Thanks in advance!
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
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.
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 [32mSTART RequestId: 238b5191-970d-1e7c-1ef1-ea9463fd1ce2 Version: $LATEST[0m [31mUnable to import module 'app': Error[0m
And this is using docker-machine and virtual box...
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,
bump, can someone weigh in? Keeping the issue open.
In addition the mapped drives (shared folders in virtual box) are /c/ to c:\ and c/Users to c:\Users
@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
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 [32mSTART RequestId: 55897d4f-56fc-134b-1d57-590ba06550d9 Version: $LATEST[0m [31mUnable to import module 'app': Error[0m [31m 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)[0m [32mEND RequestId: 55897d4f-56fc-134b-1d57-590ba06550d9[0m [32mREPORT RequestId: 55897d4f-56fc-134b-1d57-590ba06550d9 Duration: 23.03 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 30 MB [0m 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.
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.
Bump, hope someone can help
Can you try moving your project out to your own user directory? instead of C:\Intellij_projs
Sriram, thanks for still helping! Sorry though same error!
Can you try moving your project out to your own user directory? instead of C:\Intellij_projs
Same error
bump
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:
- successful run on OsX (bash, zsh)
- failed run on Windows (Docker for Windows, powershell)
- failed run on WSL (Docker for Windows, bash, zsh with
C:drive shared and mouted on both/cand/mnt/c)
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'"}
@webartoli See https://github.com/awslabs/aws-sam-cli/issues/1145#issuecomment-485811241
@jfuss Already seen, in particular on that guide I have:
- shared C: drive
- mount /c drive with this oneliner
echo "sudo mount --bind /mnt/c /c" >> ~/.bashrc && source ~/.bashrc
so ls /mnt/c and ls /c give me the same output.
Plain windows (without WSL) fail as well with the same behaviour.
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."
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.
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.