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-cli fails on build --use-container with Mac M1 + Docker Desktop (Apple Silicon) #4335

Closed
rohitspujari opened this issue Oct 25, 2022 · 1 comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/bug

Comments

@rohitspujari
Copy link

rohitspujari commented Oct 25, 2022

Description:

sam-cli is not able to discover docker desktop instance on M1 Mac even though it’s running.

Steps to reproduce:

Download SAM CLI on M1 Mac
Download Docker Desktop - Apple Silicon Version
sam init (basic hello-world python template)

Observed result:

sam build --use-container --debug  ✔ │ base Py
2022-10-24 21:00:46,379 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-10-24 21:00:46,379 | Using config file: samconfig.toml, config environment: default
2022-10-24 21:00:46,379 | Expand command line arguments to:
2022-10-24 21:00:46,379 | --template_file=/Users/ropujari/sourcecode/sam-apps/hello-world-app/template.yaml --use_container --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2022-10-24 21:00:46,683 | 'build' command is called
2022-10-24 21:00:46,683 | Starting Build inside a container
2022-10-24 21:00:46,686 | No Parameters detected in the template
2022-10-24 21:00:46,695 | 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
2022-10-24 21:00:46,695 | 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
2022-10-24 21:00:46,696 | 0 stacks found in the template
2022-10-24 21:00:46,696 | No Parameters detected in the template
2022-10-24 21:00:46,701 | 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
2022-10-24 21:00:46,701 | 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
2022-10-24 21:00:46,701 | 2 resources found in the stack
2022-10-24 21:00:46,701 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2022-10-24 21:00:46,701 | --base-dir is not presented, adjusting uri hello_world/ relative to /Users/ropujari/sourcecode/sam-apps/hello-world-app/template.yaml
2022-10-24 21:00:46,705 | Your template contains a resource with logical ID "ServerlessRestApi", which is a reserved logical ID in AWS SAM. It could result in unexpected behaviors and is not recommended.
2022-10-24 21:00:46,705 | 2 resources found in the stack
2022-10-24 21:00:46,705 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2022-10-24 21:00:46,705 | Instantiating build definitions
2022-10-24 21:00:46,707 | Same function build definition found, adding function (Previous: BuildDefinition(python3.9, /Users/ropujari/sourcecode/sam-apps/hello-world-app/hello_world, Zip, , f5122952-3304-4bc6-beaa-c3b60d46e226, {}, {}, x86_64, []), Current: BuildDefinition(python3.9, /Users/ropujari/sourcecode/sam-apps/hello-world-app/hello_world, Zip, , 20d58114-cdb9-4197-9836-544d129c024c, {}, {}, x86_64, []), Function: Function(function_id='HelloWorldFunction', name='HelloWorldFunction', functionname='HelloWorldFunction', runtime='python3.9', memory=None, timeout=3, handler='app.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/ropujari/sourcecode/sam-apps/hello-world-app/hello_world', environment=None, rolearn=None, layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'SamResourceId': 'HelloWorldFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], function_url_config=None, stack_path=''))
2022-10-24 21:00:46,708 | Building codeuri: /Users/ropujari/sourcecode/sam-apps/hello-world-app/hello_world runtime: python3.9 metadata: {} architecture: x86_64 functions: HelloWorldFunction
2022-10-24 21:00:46,708 | Building to following folder /Users/ropujari/sourcecode/sam-apps/hello-world-app/.aws-sam/build/HelloWorldFunction
2022-10-24 21:00:46,710 | Docker is not reachable
Traceback (most recent call last):
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
self.send(msg)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
self.connect()
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/util/retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/packages/six.py", line 769, in reraise
raise value.with_traceback(tb)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
self.send(msg)
File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
self.connect()
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/samcli/local/docker/utils.py", line 91, in is_docker_reachable
docker_client.ping()
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/client.py", line 187, in ping
return self.api.ping(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/api/daemon.py", line 166, in ping
return self._result(self._get(self._url('/_ping'))) == 'OK'
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/api/client.py", line 230, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Build Failed
2022-10-24 21:00:46,795 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-10-24 21:00:46,796 | Unable to find Click Context for getting session_id.
2022-10-24 21:00:46,796 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'fd034795-58f5-44fb-a1b9-92d82816407c', 'installationId': 'd79f935d-1c2d-4cfd-8e4e-7309ee985667', 'sessionId': '395514b6-ca70-4b11-a2ff-3aedf56c7f83', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'metricSpecificAttributes': {'events': [{'event_name': 'BuildWorkflowUsed', 'event_value': 'python-pip', 'thread_id': 4337649024, 'time_stamp': '2022-10-25 02:00:46.708'}]}}}]}
2022-10-24 21:00:46,797 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'af55728a-a13f-4f8f-be93-e24b356e53ae', 'installationId': 'd79f935d-1c2d-4cfd-8e4e-7309ee985667', 'sessionId': '395514b6-ca70-4b11-a2ff-3aedf56c7f83', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '9cc71a82fa32e1ef8ce7675eb7724d9bfab5eecebf39e01295ae5098e0f80143', 'initialCommit': None}, 'duration': 415, 'exitReason': 'BuildInsideContainerError', 'exitCode': 1}}]}
2022-10-24 21:00:47,205 | Telemetry response: 200
Error: Docker is unreachable. Docker needs to be running to build inside a container.
2022-10-24 21:00:47,212 | Telemetry response: 200

Expected result:

If I build locally (without --use-container, this command succeeds. But when I try to local testing (sam local start-api --debug), it complains "Running AWS SAM projects locally requires Docker. Have you got it installed and running?" even though docker is running.

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

  1. OS: Monterey 12.6, Apple M1
  2. sam --version: 1.60.0
  3. AWS region: NA
@rohitspujari rohitspujari added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/bug labels Oct 25, 2022
@mndeveci
Copy link
Contributor

This is a duplicate of #4329

Please see this comment for the workaround: #4329 (comment)

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. type/bug
Projects
None yet
Development

No branches or pull requests

2 participants