aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Sam local command does not work on Ubuntu 16.04 venv

Open IsraelGboluwaga opened this issue 7 years ago • 27 comments

Sam local does not work on Ubuntu 16.04 venv

Trying to run sam local start-api, I ran into a docker blocker. Asking for installation, even though installed.

Steps to reproduce

Run sam local start-api

Observed result

2019-01-09 14:14:55 Found credentials in shared credentials file: ~/.aws/credentials
Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

With the --debug flag set:

2019-01-09 14:19:29 Using SAM Template at /home/israel/lambda/sam-app/template.yaml
2019-01-09 14:19:29 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-01-09 14:19:29 Changing event name from before-call.apigateway to before-call.api-gateway
2019-01-09 14:19:29 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-01-09 14:19:29 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-01-09 14:19:29 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-01-09 14:19:29 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-01-09 14:19:29 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-01-09 14:19:29 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-01-09 14:19:29 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-01-09 14:19:29 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-01-09 14:19:29 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-01-09 14:19:29 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-01-09 14:19:29 Changing event name from before-call.apigateway to before-call.api-gateway
2019-01-09 14:19:29 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-01-09 14:19:29 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-01-09 14:19:29 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-01-09 14:19:29 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-01-09 14:19:29 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-01-09 14:19:29 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-01-09 14:19:29 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-01-09 14:19:29 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-01-09 14:19:29 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-01-09 14:19:29 local start-api command is called
2019-01-09 14:19:29 Looking for credentials via: env
2019-01-09 14:19:29 Looking for credentials via: assume-role
2019-01-09 14:19:29 Looking for credentials via: shared-credentials-file
2019-01-09 14:19:29 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-09 14:19:29 Loading JSON file: /home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/botocore/data/endpoints.json
2019-01-09 14:19:29 Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f6181c3a8c0>
2019-01-09 14:19:29 Loading JSON file: /home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/botocore/data/serverlessrepo/2017-09-08/service-2.json
2019-01-09 14:19:29 Event creating-client-class.serverlessapplicationrepository: calling handler <function add_generate_presigned_url at 0x7f6181c64230>
2019-01-09 14:19:29 The s3 config key is not a dictionary type, ignoring its value of: None
2019-01-09 14:19:29 Setting serverlessrepo timeout as (60, 60)
2019-01-09 14:19:29 Loading JSON file: /home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/botocore/data/_retry.json
2019-01-09 14:19:29 Registering retry handlers for service: serverlessrepo
2019-01-09 14:19:29 No Parameters detected in the template
2019-01-09 14:19:29 2 resources found in the template
2019-01-09 14:19:29 Found Serverless function with name='HelloWorldFunction' and CodeUri='hello-world/'
2019-01-09 14:19:29 Trying paths: ['/home/israel/.docker/config.json', '/home/israel/.dockercfg']
2019-01-09 14:19:29 No config file found
2019-01-09 14:19:29 Trying paths: ['/home/israel/.docker/config.json', '/home/israel/.dockercfg']
2019-01-09 14:19:29 No config file found
2019-01-09 14:19:29 Docker is not reachable
Traceback (most recent call last):
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/samcli/local/docker/manager.py", line 50, in is_docker_reachable
    self.docker_client.ping()
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/docker/client.py", line 187, in ping
    return self.api.ping(*args, **kwargs)
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/docker/api/daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/docker/api/client.py", line 215, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/israel/lambda/AWS-AppSync-Lambda-GraphQL-API/venv/local/lib/python2.7/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

Note: I'm running it in a virtual environment using Python 2.7.12

Expected result

Normal function execution

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

  1. OS: Ubuntu 16.04 LTS
  2. sam --version: 0.10.0

IsraelGboluwaga avatar Jan 09 '19 13:01 IsraelGboluwaga

Is docker running on your machine?

jfuss avatar Jan 09 '19 14:01 jfuss

Yes, it is.

IsraelGboluwaga avatar Jan 09 '19 14:01 IsraelGboluwaga

SAM CLI can't ping the docker daemon, meaning it either isn't installed or its not currently running.

Are you able to interact with docker through the command line outside of SAM CLI? docker container run hello-world

jfuss avatar Jan 09 '19 14:01 jfuss

I got this output from docker container run hello-world:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

IsraelGboluwaga avatar Jan 09 '19 14:01 IsraelGboluwaga

Looks like the key piece is this: ConnectionError: ('Connection aborted.', error(13, 'Permission denied')). Docker saying the user needs access to the docker group. What is weird is that you can run docker from the command line. Did you follow https://docs.docker.com/install/linux/linux-postinstall/ when installing docker?

jfuss avatar Jan 09 '19 14:01 jfuss

Did you follow https://docs.docker.com/install/linux/linux-postinstall/ when installing docker? => I just did. Didn't change anything.

IsraelGboluwaga avatar Jan 09 '19 14:01 IsraelGboluwaga

Is there anything else I can do, please @jfuss ?

IsraelGboluwaga avatar Jan 09 '19 15:01 IsraelGboluwaga

It's something to do with your docker service on ubuntu, not with aws sam.

Stupid question, have you rebooted the machine? Sometimes it works for me when I log out of my user to ensure ALL user stuff is logged out.

DevOpsChris avatar Jan 09 '19 15:01 DevOpsChris

I'll restart my machine now and give feedback. Thanks @DevOpsChris

I apologize for my stupid question. Try to be nicer too.

IsraelGboluwaga avatar Jan 09 '19 16:01 IsraelGboluwaga

Oh that got lost in translation. I'm sorry.

"Stupid question", was describing "have you rebooted the machine?" It's a way of asking a question without assumptions, even if it does sound silly. Meaning: My question was stupid, not yours.

It was not to describe your question for this issue that you started.

Not having a tech work easily is frustrating. Hope this helps!

DevOpsChris avatar Jan 09 '19 16:01 DevOpsChris

lol... It's okay. I read that over and got it. I'm sorry for misunderstanding you.

It worked after restarting my system. Thank you so much @DevOpsChris Once again, forgive me for misunderstanding. Enjoy the rest of your day.

IsraelGboluwaga avatar Jan 09 '19 16:01 IsraelGboluwaga

Please close this issue when you can. It's been solved. :)

DevOpsChris avatar Jan 10 '19 00:01 DevOpsChris

Rebooting after sam-cli installation helped me too. Maybe this could be added to the installation manual. :relaxed:

freddie-freeloader avatar Nov 21 '19 14:11 freddie-freeloader

sadly, rebooting haven't worked for me - followed all the above too, on ubuntu 20.04

maglkp avatar Jun 07 '20 20:06 maglkp

Rebooting isn't working for me either. Does anyone have other solutions?

KueiChinHuang avatar Jun 18 '20 00:06 KueiChinHuang

me too (on WSL2, ubuntu 20.04), rebooting virtual ubuntu and even windows didn't solve it :(

Tilko avatar Aug 16 '20 21:08 Tilko

Add your current user to the docker user group may help.

hikui avatar Aug 30 '20 05:08 hikui

I also need solution.. getting same error. User is already added to docker group sam local start-api Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

rajanpanchal avatar Sep 12 '20 22:09 rajanpanchal

My Conditions

  • Ubuntu 18.04
  • Docker in /usr/bin/docker was working like a boss Docker version 19.03.13, build 4484c46d9d
  • Ran sam local invoke HelloWorldFunction -e events/event.json, yielded the following
Running AWS SAM projects locally requires Docker. Have you got it installed?

What Worked

  1. Visited Docker's post-installation recommendations
  2. Created group docker (I already had it)
    sudo groupadd docker
    groupadd: group 'docker' already exists
    
  3. Added my user to the docker group
    sudo usermod -aG docker $USER
    
  4. Rebooted my machine, ran the sam command again, exhaled, smiled
    sam local invoke HelloWorldFunction -e events/event.json
    

fusion27 avatar Oct 04 '20 16:10 fusion27

My Conditions

  • Ubuntu 18.04
  • Ran sam local invoke HelloWorldFunction -e events/event.json, yielded the following
Running AWS SAM projects locally requires Docker. Have you got it installed?

What Worked

  1. Visited Docker's post-installation recommendations
  2. Created group docker (I already had it)
    sudo groupadd docker
    groupadd: group 'docker' already exists
    
  3. Added my user to the docker group
    sudo usermod -aG docker $USER
    
  4. Rebooted my machine, ran the sam command again, exhaled, smiled
    sam local invoke HelloWorldFunction -e events/event.json
    

For me, user was already added to the group and was still getting error. What worked for me was running the command with sudo su

rajanpanchal avatar Oct 04 '20 16:10 rajanpanchal