Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "SAM CLI has an invalid version" error when trying to debug python hello world lambda in Visual Studio Code #6415

Closed
JohnHoward9 opened this issue Dec 7, 2023 · 3 comments
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@JohnHoward9
Copy link

Description:

I'm getting a "SamLaunchRequestError: SAM CLI has an invalid version [InvalidSamCliVersion]" when trying to launch an aws-sam/direct-invoke debug configuration in Visual Studio Code.

Steps to reproduce:

Install Visual Studio Code
Install the latest version of the AWS Toolkit
Install the latest version of the SAM CLI (I installed version 1,.86.1 using the brew utility).
Create the following debug configuration in the .vscode/launch.json file (adapt as required):

        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "src:app.lambda_handler (python3.11)",
            "invokeTarget": {
                "target": "code",
                "projectRoot": "${workspaceFolder}/src",
                "lambdaHandler": "app.lambda_handler"
            },
            "lambda": {
                "runtime": "python3.11",
                "payload": {},
                "environmentVariables": {}
            },
            "aws": {
              "credentials": "profile:xxxxxxxx",
              "region": "eu-west-1"
            }
        }

Observed result:

aws_toolkit log has the following error
2023-12-07 15:53:36 [ERROR]: SamLaunchRequestError: SAM CLI has an invalid version [InvalidSamCliVersion]

Also get the notification
SAM CLI 1.85-1.86 has known issues on Windows. Update SAM CLI.

But, cannot find SAM version 1.104.0 installed

Expected result:

The debug session should be launched successfully within Visual Studio Code

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

OS - Windows 11
Docker version 24.0.7, build afdd53b
SAM CLI, version 1.104.0
Region - eu-west-1

Traceback (most recent call last):
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\connectionpool.py", line 462, in _make_request
    httplib_response = conn.getresponse()
                       ^^^^^^^^^^^^^^^^^^
  File "http\client.py", line 1378, in getresponse
  File "http\client.py", line 318, in begin
  File "http\client.py", line 279, in _read_status
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\transport\npipesocket.py", line 224, in readinto
    return self.sock.recv_into(buf)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\transport\npipesocket.py", line 25, in wrapped
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\transport\npipesocket.py", line 151, in recv_into
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\connectionpool.py", line 799, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\util\retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\packages\six.py", line 770, in reraise
    raise value
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\connectionpool.py", line 469, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\urllib3\connectionpool.py", line 358, in _raise_timeout
    raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: NpipeHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\__main__.py", line 12, in <module>
    cli(prog_name="sam")
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1077, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1644, in parse_args
    rest = super().parse_args(ctx, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 2362, in process_value
    value = self.callback(ctx, self, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\cli\main.py", line 58, in print_info
    "additional_dependencies": gather_additional_dependencies_info(),
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\utils\system_info.py", line 37, in gather_additional_dependencies_info
    "docker_engine": _gather_docker_info(),
                     ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\utils\system_info.py", line 61, in _gather_docker_info
    if is_docker_reachable(client):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\local\docker\utils.py", line 91, in is_docker_reachable
    docker_client.ping()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\client.py", line 203, in ping
    return self.api.ping(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\api\daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\utils\decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\docker\api\client.py", line 237, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\requests\sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\requests\adapters.py", line 532, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: NpipeHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

Related issue

@JohnHoward9 JohnHoward9 added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Dec 7, 2023
@JohnHoward9
Copy link
Author

Resolved this by removing the credsStore ("credsStore": "desktop") entry from my ~/.docker/config.json file. This was suggested here:

sam local invoke - StoreError #5516

@sriram-mv
Copy link
Contributor

1.86.1 is an old version of AWS SAM CLI. Here's a doc to switch to the latest version: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.html#manage-sam-cli-versions-switch

Glad you were able to figure out the issue!

Copy link
Contributor

github-actions bot commented Dec 8, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

2 participants