Search code examples
aws-lambdaaws-cliaws-sam-cliaws-sam

`sam local invoke`error 'NameError: name 'NpipeHTTPAdapter' is not defined'


I am writing a lambda function just to get some data from an AWS RDS table. I am able to successfully run sam package and sam deploy to deploy the function to AWS.

When I run sam build it successfully builds and then I run sam local invoke to test the lambda locally, but I get the following error output

$ sam local invoke
Traceback (most recent call last):
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\docker\api\client.py", line 154, in __init__
    self._custom_adapter = NpipeHTTPAdapter(
NameError: name 'NpipeHTTPAdapter' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\jthomas\AppData\Local\Programs\Python\Python38-32\Scripts\sam.exe\__main__.py", line 7, in <module>
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\lib\telemetry\metrics.py", line 93, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\lib\telemetry\metrics.py", line 62, in wrapped
    return_value = func(*args, **kwargs)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\commands\local\invoke\cli.py", line 70, in cli
    do_cli(
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\commands\local\invoke\cli.py", line 131, in do_cli
    with InvokeContext(
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\commands\local\cli_common\invoke_context.py", line 134, in __enter__
    self._container_manager = self._get_container_manager(self._docker_network, self._skip_pull_image)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\commands\local\cli_common\invoke_context.py", line 373, in _get_container_manager
    return ContainerManager(docker_network_id=docker_network, skip_pull_image=skip_pull_image)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\samcli\local\docker\manager.py", line 34, in __init__
    self.docker_client = docker_client or docker.from_env()
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\docker\client.py", line 84, in from_env
    return cls(
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\docker\client.py", line 40, in __init__
    self.api = APIClient(*args, **kwargs)
  File "c:\users\jthomas\appdata\local\programs\python\python38-32\lib\site-packages\docker\api\client.py", line 158, in __init__
    raise DockerException(
docker.errors.DockerException: Install pypiwin32 package to enable npipe:// support

My versions:

$ python --version
Python 3.8.0
$ aws --version
aws-cli/1.16.286 Python/3.6.0 Windows/10 botocore/1.13.22
$ sam --version
SAM CLI, version 0.33.1

Pip list shows that I have pypiwin32 (v223) installed

$ pip list
Package             Version
------------------- ---------
arrow               0.15.4
attrs               19.3.0
aws-lambda-builders 0.6.0
aws-sam-cli         0.33.1
aws-sam-translator  1.15.1
binaryornot         0.4.4
boto3               1.10.22
botocore            1.13.22
certifi             2019.9.11
chardet             3.0.4
chevron             0.13.1
Click               7.0
cookiecutter        1.6.0
dateparser          0.7.2
docker              4.1.0
docutils            0.15.2
Flask               1.0.4
future              0.18.2
idna                2.8
itsdangerous        1.1.0
Jinja2              2.10.3
jinja2-time         0.2.0
jmespath            0.9.4
jsonschema          3.2.0
MarkupSafe          1.1.1
pip                 19.3.1
poyo                0.5.0
pypiwin32           223
pyrsistent          0.15.5
python-dateutil     2.8.0
pytz                2019.3
pywin32             225
PyYAML              5.1.2
regex               2019.11.1
requests            2.22.0
s3transfer          0.2.1
serverlessrepo      0.1.9
setuptools          41.6.0
six                 1.13.0
tomlkit             0.5.8
tzlocal             2.0.0
urllib3             1.25.7
websocket-client    0.56.0
Werkzeug            0.16.0
wheel               0.33.6
whichcraft          0.6.1

Docker Desktop is also installed and running on my machine. I have been on https://github.com/docker/compose/issues/4842 and tried to install aws-sam-cli via the MSI but that did not work. I have reinstalled Python, AWS CLI, AWS SAM CLI, and Docker. I am not sure where to go next.

Is there any fix to get my AWS Lambda functions running locally?


Solution

  • I ended up needing to uninstall the version of sam-cli I installed via pip and use the Windows MSI installer instead. Apparently using the MSI is the required installation method for Windows. And then use 'sam.cmd' to invoke the sam cli.