aws-sam-cli: Hello world fails to build on Windows 10

Description

Python version of hello-world fails to build on Windows 10

Steps to reproduce

I can reproduce it in 2 ways. First way to reproduce:

sam init --runtime=python3.6 cd sam-app sam build --use-container

Can also be reproduced if I do the following: Step 0: (if necessary to clean up from above steps, in WSL): cd …;rm -rf sam-app sam init --runtime=python3.6 cd sam-app sam build sam local start-api --debug

This seems to only happen on my machine, but I don’t know how to recover. I tried to reinstall Python, the AWS CLI, SAM CLI, docker, and I’m having no luck.

Observed result

PS C:\proj\sls\sam-app> sam local start-api --debug 2018-12-10 12:11:01 Using SAM Template at C:\proj\sls\sam-app.aws-sam\build\templat 2018-12-10 12:11:01 Changing event name from creating-client-class.iot-data to creat 2018-12-10 12:11:01 Changing event name from before-call.apigateway to before-call.a 2018-12-10 12:11:01 Changing event name from request-created.machinelearning.Predict .Predict 2018-12-10 12:11:01 Changing event name from before-parameter-build.autoscaling.Crea meter-build.auto-scaling.CreateLaunchConfiguration 2018-12-10 12:11:01 Changing event name from before-parameter-build.route53 to befor 2018-12-10 12:11:01 Changing event name from request-created.cloudsearchdomain.Searc ain.Search 2018-12-10 12:11:01 Changing event name from docs..autoscaling.CreateLaunchConfigur o-scaling.CreateLaunchConfiguration.complete-section 2018-12-10 12:11:01 Changing event name from before-parameter-build.logs.CreateExpor dwatch-logs.CreateExportTask 2018-12-10 12:11:01 Changing event name from docs..logs.CreateExportTask.complete-s ateExportTask.complete-section 2018-12-10 12:11:01 Changing event name from before-parameter-build.cloudsearchdomai loudsearch-domain.Search 2018-12-10 12:11:01 Changing event name from docs..cloudsearchdomain.Search.complet in.Search.complete-section 2018-12-10 12:11:01 Changing event name from creating-client-class.iot-data to creat 2018-12-10 12:11:01 Changing event name from before-call.apigateway to before-call.a 2018-12-10 12:11:01 Changing event name from request-created.machinelearning.Predict .Predict 2018-12-10 12:11:01 Changing event name from before-parameter-build.autoscaling.Crea meter-build.auto-scaling.CreateLaunchConfiguration 2018-12-10 12:11:01 Changing event name from before-parameter-build.route53 to befor 2018-12-10 12:11:01 Changing event name from request-created.cloudsearchdomain.Searc ain.Search 2018-12-10 12:11:01 Changing event name from docs..autoscaling.CreateLaunchConfigur o-scaling.CreateLaunchConfiguration.complete-section 2018-12-10 12:11:01 Changing event name from before-parameter-build.logs.CreateExpor dwatch-logs.CreateExportTask 2018-12-10 12:11:01 Changing event name from docs..logs.CreateExportTask.complete-s ateExportTask.complete-section 2018-12-10 12:11:01 Changing event name from before-parameter-build.cloudsearchdomai loudsearch-domain.Search 2018-12-10 12:11:01 Changing event name from docs..cloudsearchdomain.Search.complet in.Search.complete-section 2018-12-10 12:11:01 local start-api command is called 2018-12-10 12:11:01 Looking for credentials via: env 2018-12-10 12:11:01 Looking for credentials via: assume-role 2018-12-10 12:11:01 Looking for credentials via: shared-credentials-file 2018-12-10 12:11:01 Found credentials in shared credentials file: ~/.aws/credentials 2018-12-10 12:11:01 Loading JSON file: c:\program files\python36\lib\site-packages\b 2018-12-10 12:11:01 Event choose-service-name: calling handler <function handle_serv

2018-12-10 12:11:01 Loading JSON file: c:\program files\python36\lib\site-packages\b 08\service-2.json 2018-12-10 12:11:01 Event creating-client-class.serverlessapplicationrepository: cal presigned_url at 0x0000024E419F7A60> 2018-12-10 12:11:01 The s3 config key is not a dictionary type, ignoring its value o 2018-12-10 12:11:01 Setting serverlessrepo timeout as (60, 60) 2018-12-10 12:11:01 Loading JSON file: c:\program files\python36\lib\site-packages\b 2018-12-10 12:11:01 Registering retry handlers for service: serverlessrepo 2018-12-10 12:11:01 No Parameters detected in the template 2018-12-10 12:11:01 2 resources found in the template 2018-12-10 12:11:01 Found Serverless function with name=‘HelloWorldFunction’ and Cod 2018-12-10 12:11:01 Trying paths: [‘C:\Users\mkislik\.docker\config.json’, 'C:\ 2018-12-10 12:11:01 Found file at path: C:\Users\mkislik.docker\config.json 2018-12-10 12:11:01 Found ‘auths’ section 2018-12-10 12:11:01 Auth data for https://index.docker.io/v1/ is absent. Client migh ad. 2018-12-10 12:11:01 Found ‘credsStore’ section Traceback (most recent call last): File “c:\program files\python36\lib\site-packages\docker\api\client.py”, line 140, self._custom_adapter = NpipeAdapter( NameError: name ‘NpipeAdapter’ is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “c:\program files\python36\lib\runpy.py”, line 193, in _run_module_as_main “main”, mod_spec) File “c:\program files\python36\lib\runpy.py”, line 85, in run_code exec(code, run_globals) File "C:\Program Files\Python36\Scripts\sam.exe_main.py", line 9, in <module> File “c:\program files\python36\lib\site-packages\click\core.py”, line 722, in __c return self.main(*args, **kwargs) File “c:\program files\python36\lib\site-packages\click\core.py”, line 697, in mai rv = self.invoke(ctx) File “c:\program files\python36\lib\site-packages\click\core.py”, line 1066, in in return process_result(sub_ctx.command.invoke(sub_ctx)) File “c:\program files\python36\lib\site-packages\click\core.py”, line 1066, in in return process_result(sub_ctx.command.invoke(sub_ctx)) File “c:\program files\python36\lib\site-packages\click\core.py”, line 895, in inv return ctx.invoke(self.callback, **ctx.params) File “c:\program files\python36\lib\site-packages\click\core.py”, line 535, in inv return callback(*args, **kwargs) File “c:\program files\python36\lib\site-packages\click\decorators.py”, line 64, i return ctx.invoke(f, obj, *args[1:], **kwargs) File “c:\program files\python36\lib\site-packages\click\core.py”, line 535, in inv return callback(*args, **kwargs) File "c:\program files\python36\lib\site-packages\samcli\commands\local\start_api
parameter_overrides) # pragma: no cover File "c:\program files\python36\lib\site-packages\samcli\commands\local\start_api
aws_region=ctx.region) as invoke_context: File "c:\program files\python36\lib\site-packages\samcli\commands\local\cli_common enter
self._check_docker_connectivity() File "c:\program files\python36\lib\site-packages\samcli\commands\local\cli_common heck_docker_connectivity docker_client = docker_client or docker.from_env() File “c:\program files\python36\lib\site-packages\docker\client.py”, line 85, in f timeout=timeout, version=version, **kwargs_from_env(**kwargs) File “c:\program files\python36\lib\site-packages\docker\client.py”, line 40, in _ self.api = APIClient(*args, **kwargs) File “c:\program files\python36\lib\site-packages\docker\api\client.py”, line 145, ‘Install pypiwin32 package to enable npipe:// support’ docker.errors.DockerException: Install pypiwin32 package to enable npipe:// support

Expected result

Running server I believe on port 3000, returning “hello world”.

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

  1. OS:

Windows 10

  1. sam --version:

SAM CLI, version 0.8.1

Add --debug flag to command you are running

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (7 by maintainers)

Most upvoted comments

So I installed sam-cli using msi and I was getting this issue. I tried everything in this thread and reinstalled everything, but the issue persisted nevertheless.

It turns out sam-cli is using a different python installation at runtime, and for me, it is located in
C:\Program Files\Amazon\AWSSAMCLI\runtime
This thing uses docker-4.0.4 which is outdated so I ran ./python -m pip install --upgrade docker in the runtime folder, and after upgrading to docker-5.0.3 I am longer facing the issue.

I don’t see the option to reopen this issue.

I remember working around the issue by: downgrading pypiwin32=220, but that was around 10 months ago. Others are saying downgrading pywin32 from version 225 to 224 worked for them.

I also asked AWS to document this problem and the solution, but that did not happen, either.

@mkislik Thanks! It looks like this issue was caused by an out-of-date version of the ‘docker’ pip package.

None of the following had any effect:

  1. Remove python 3.6.8 and install python 3.6.7.
  2. Update the awscli package: python -m pip install --upgrade awscli
  3. Install the aws-sam-cli package: python -m pip install aws-sam-cli
  4. Restart my machine.

But this fixed the issue:

  1. Update the docker package from 3.4.0 to 3.7.0: python -m pip install --upgrade docker
PS C:\repos\t1> python --version
Python 3.6.7
PS C:\repos\t1> python -m pip freeze
arrow==0.12.1
astroid==2.0.4
aws-lambda-builders==0.0.5
aws-sam-cli==0.10.0
aws-sam-translator==1.9.0
awscli==1.16.93
binaryornot==0.4.4
boto3==1.9.83
botocore==1.12.83
certifi==2018.4.16
chardet==3.0.4
chevron==0.13.1
click==6.7
colorama==0.3.9
cookiecutter==1.6.0
dateparser==0.7.0
docker==3.7.0
docker-pycreds==0.4.0
docutils==0.14
enum34==1.1.6
Flask==1.0.2
future==0.16.0
idna==2.7
isort==4.3.4
itsdangerous==0.24
Jinja2==2.10
jinja2-time==0.2.0
jmespath==0.9.3
jsonschema==2.6.0
lazy-object-proxy==1.3.1
MarkupSafe==1.0
mccabe==0.6.1
poyo==0.4.1
pyasn1==0.4.3
pylint==2.1.1
pypiwin32==223
pystache==0.5.4
python-dateutil==2.7.3
pytz==2018.5
pywin32==224
PyYAML==3.12
regex==2018.8.29
requests==2.20.1
rsa==3.4.2
s3transfer==0.1.13
serverlessrepo==0.1.5
six==1.11.0
typed-ast==1.1.0
tzlocal==1.5.1
urllib3==1.23
websocket-client==0.48.0
Werkzeug==0.14.1
whichcraft==0.4.1
wrapt==1.10.11
PS C:\repos\t1> sam build
2019-01-23 15:52:39 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-23 15:52:39 Building resource 'HelloWorldFunction'
2019-01-23 15:52:39 'nodejs' runtime has not been validated!
2019-01-23 15:52:39 Running NodejsNpmBuilder:NpmPack
2019-01-23 15:52:40 Running NodejsNpmBuilder:CopySource
2019-01-23 15:52:40 Running NodejsNpmBuilder:NpmInstall

Build Succeeded

Built Artifacts  : .aws-sam\build
Built Template   : .aws-sam\build\template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Package: sam package --s3-bucket <yourbucket>

PS C:\repos\t1> echo '{}' | sam local invoke HelloWorldFunction
2019-01-23 15:52:48 Reading invoke payload from stdin (you can also pass it from file with --event)
2019-01-23 15:52:48 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-23 15:52:48 Invoking app.lambdaHandler (nodejs8.10)

Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-01-23 15:52:49 Mounting C:\repos\t1\.aws-sam\build\HelloWorldFunction as /var/task:ro inside runtime container
START RequestId: f80782ca-3f07-163f-9e20-efc980427f3c 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: f80782ca-3f07-163f-9e20-efc980427f3c
REPORT RequestId: f80782ca-3f07-163f-9e20-efc980427f3c  Duration: 2.35 ms       Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 31 MB

{"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)"]}

I’m investigating the new error now, but it looks like an unrelated issue. Edit: Un-sharing and then re-sharing my C drive with Docker fixed the new issue.

So the question is: Why was my docker dependency out of date despite just installing SAM CLI 0.10 yesterday? Should the minimum version be updated in SAM CLI’s dependencies?