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

Bug: sam local start-api - AttributeError #7043

Closed
anand2k24 opened this issue May 10, 2024 · 9 comments
Closed

Bug: sam local start-api - AttributeError #7043

anand2k24 opened this issue May 10, 2024 · 9 comments
Labels
area/docker blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days type/question

Comments

@anand2k24
Copy link

anand2k24 commented May 10, 2024

Description:

when started this command sam local start-api --port 8080

Steps to reproduce:

C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent>sam local start-api --port 8080

Error: 'APIClient' object has no attribute '_custom_adapter'
Traceback:
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\cli\cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\lib\telemetry\metric.py", line 185, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\lib\telemetry\metric.py", line 150, in wrapped
    return_value = func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\lib\utils\version_checker.py", line 43, in wrapped
    actual_result = func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\cli\main.py", line 95, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\commands\local\start_api\cli.py", line 150, in cli
    do_cli(
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\commands\local\start_api\cli.py", line 232, in do_cli
    with InvokeContext(
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\commands\local\cli_common\invoke_context.py", line 273, in __enter__
    if not self._container_manager.is_docker_reachable:
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\local\docker\manager.py", line 56, in is_docker_reachable
    return utils.is_docker_reachable(self.docker_client)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\local\docker\utils.py", line 91, in is_docker_reachable
    docker_client.ping()
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\client.py", line 201, in ping
    return self.api.ping(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\utils\decorators.py", line 44, in inner
    return f(self, *args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\client.py", line 236, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 697, in send
    adapter = self.get_adapter(url=request.url)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\client.py", line 499, in get_adapter
    if self._custom_adapter:

An unexpected error was encountered while executing "sam local start-api".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20local%20start-api%20-%20AttributeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20local%20start-api%20-%20AttributeError

Observed result:

C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent>sam local start-api -p 8080 -d 5858 --debug
2024-05-10 12:29:14,050 | Config file location: C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\samconfig.toml
2024-05-10 12:29:14,056 | Loading configuration values from [default.['local', 'start-api'].parameters] (env.command_name.section) in
config file at 'C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\samconfig.toml'...
2024-05-10 12:29:14,061 | Configuration values successfully loaded.
2024-05-10 12:29:14,062 | Configuration values are: {'stack_name': 'jenkins-agent', 'warm_containers': 'EAGER'}
2024-05-10 12:29:14,088 | Using SAM Template at C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\template.yaml
2024-05-10 12:29:14,155 | Using config file: samconfig.toml, config environment: default
2024-05-10 12:29:14,157 | Expand command line arguments to:
2024-05-10 12:29:14,159 | --template_file=C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\template.yaml --port=8080
--debug_port=(5858,) --host=127.0.0.1 --static_dir=public --layer_cache_basedir=C:\Users\sam_user\AppData\Roaming\AWS
SAM\layers-pkg --warm_containers=EAGER --container_host=localhost --container_host_interface=127.0.0.1
2024-05-10 12:29:15,522 | local start-api command is called
2024-05-10 12:29:15,529 | No Parameters detected in the template
2024-05-10 12:29:15,629 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the
resource logical id as the resource id
2024-05-10 12:29:15,635 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the
resource logical id as the resource id
2024-05-10 12:29:15,635 | 0 stacks found in the template
2024-05-10 12:29:15,639 | No Parameters detected in the template
2024-05-10 12:29:15,665 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the
resource logical id as the resource id
2024-05-10 12:29:15,665 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the
resource logical id as the resource id
2024-05-10 12:29:15,671 | 2 resources found in the stack
2024-05-10 12:29:15,675 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2024-05-10 12:29:15,675 | --base-dir is not presented, adjusting uri hello_world/ relative to
C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\template.yaml
2024-05-10 12:29:15,675 | watch resource C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\template.yaml
2024-05-10 12:29:15,683 | Create Observer for resource C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\template.yaml with
recursive True
2024-05-10 12:29:15,685 | watch resource C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent\template.yaml's parent
C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent
2024-05-10 12:29:15,689 | Create Observer for resource C:\Users\sam_user\ws\as\Lambda\jenkins\jenkins-agent with recursive False
2024-05-10 12:29:15,719 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-05-10 12:29:18,449 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-05-10 12:29:18,450 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '696d411b-2574-47a7-8a27-5808fc9c640d',
'installationId': '51e10658-ca80-4ae0-8214-7738fad91b84', 'sessionId': 'c56d2226-6f77-4fef-9094-16a64c4442bd',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.9.13', 'samcliVersion': '1.116.0', 'awsProfileProvided': False,
'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-api', 'metricSpecificAttributes': {'projectType': 'CFN',
'gitOrigin': None, 'projectName': 'b28e3fa5181c0f270db6a279de41018f3685140ea88759182cb053c5b8b07a7f', 'initialCommit': None},
'duration': 1567, 'exitReason': 'AttributeError', 'exitCode': 255}}]}
2024-05-10 12:29:18,451 | Unable to find Click Context for getting session_id.
2024-05-10 12:29:18,460 | Sending Telemetry: {'metrics': [{'events': {'requestId': '133e08db-1076-4cad-b96b-b40b22ff7bfb',
'installationId': '51e10658-ca80-4ae0-8214-7738fad91b84', 'sessionId': 'c56d2226-6f77-4fef-9094-16a64c4442bd',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.9.13', 'samcliVersion': '1.116.0', 'commandName': 'sam local start-api',
'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id':
'bd8f7d776f0644f7b21d8fb4c6474537', 'time_stamp': '2024-05-10 06:59:14.049', 'exception_name': None}, {'event_name':
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '959412a0c35149eb8fa624ff6e4b8272', 'time_stamp': '2024-05-10
06:59:14.155', 'exception_name': None}]}}}]}
2024-05-10 12:29:19,111 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed
out. (read timeout=0.1)
2024-05-10 12:29:19,152 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed
out. (read timeout=0.1)

Error: 'APIClient' object has no attribute '_custom_adapter'
Traceback:
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\cli\cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\lib\telemetry\metric.py", line 185, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\lib\telemetry\metric.py", line 150, in wrapped
    return_value = func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\lib\utils\version_checker.py", line 43, in wrapped
    actual_result = func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\cli\main.py", line 95, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\commands\local\start_api\cli.py", line 150, in cli
    do_cli(
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\commands\local\start_api\cli.py", line 232, in do_cli
    with InvokeContext(
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\commands\local\cli_common\invoke_context.py", line 273, in __enter__
    if not self._container_manager.is_docker_reachable:
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\local\docker\manager.py", line 56, in is_docker_reachable
    return utils.is_docker_reachable(self.docker_client)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\samcli\local\docker\utils.py", line 91, in is_docker_reachable
    docker_client.ping()
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\client.py", line 201, in ping
    return self.api.ping(*args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\utils\decorators.py", line 44, in inner
    return f(self, *args, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\client.py", line 236, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 697, in send
    adapter = self.get_adapter(url=request.url)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\client.py", line 499, in get_adapter
    if self._custom_adapter:

An unexpected error was encountered while executing "sam local start-api".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20local%20start-api%20-%20AttributeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20local%20start-api%20-%20AttributeError

Expected result:

it should start without error

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

Windows

  1. OS: Windows
  2. sam --version:SAM CLI, version 1.116.0
  3. AWS region: xx-xxxx-1
# Paste the output of `sam --info` here

Traceback (most recent call last):
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\docker\api\client.py", line 497, in get_adapter
    return super().get_adapter(url)
  File "C:\Users\sam_user\.pyenv\pyenv-win\versions\3.9.13\lib\site-packages\requests\sessions.py", line 794, in get_adapter
    raise InvalidSchema(f"No connection adapters were found for {url!r}")
requests.exceptions.InvalidSchema: No connection adapters were found for 'npipe:/v1.35/_ping'

Add --debug flag to command you are running

@anand2k24 anand2k24 added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label May 10, 2024
@hawflau
Copy link
Contributor

hawflau commented May 10, 2024

Hey @anand2k24 thanks for raising the issue.

It looks like the issue came from docker. Do you have docker properly installed and running?

@hawflau hawflau added area/docker type/question and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 10, 2024
@anand2k24
Copy link
Author

anand2k24 commented May 10, 2024 via email

@hawflau hawflau added the blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days label May 10, 2024
@hawflau
Copy link
Contributor

hawflau commented May 13, 2024

SAM CLI uses Docker SDK under the hood. We cannot guarantee podman is compatible with Docker's API.

Can you switch to use docker?

@anand2k24
Copy link
Author

anand2k24 commented May 13, 2024 via email

@mndeveci
Copy link
Contributor

If podman supports Docker APIs then this should work as well.

Looking at the file paths, I assume that you are using a SAM CLI version which is installed through pip? If so can you use official installers (for your case it is MSI) to see if it is going to fix the problem?

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html

@anand2k24
Copy link
Author

anand2k24 commented May 20, 2024 via email

@lucashuy
Copy link
Contributor

Thanks for following up with us. The Windows SAM CLI installer we distribute uses docker==7.0.0. This shouldn't be an issue for those using our provided .msi installer files.

For the permission denied issue, we would require some additional information to help diagnose this (ie. providing a template and/or reproducible project), but glad to hear that you found a workaround for the issue you faced.

@lucashuy
Copy link
Contributor

Closing the issue, please create a new issue if you encounter any other issues.

Copy link
Contributor

⚠️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
area/docker blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days type/question
Projects
None yet
Development

No branches or pull requests

4 participants