Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Sam can't find docker

I'm trying to test my hello world lambda function with aws-sam-cli using the following command in my project root folder:

sam local start-api --debug

This gives me the following output in the console:

2018-07-11 16:13:15 local start-api command is called
2018-07-11 16:13:15 2 resources found in the template
2018-07-11 16:13:15 Found Serverless function with name='Hello' and CodeUri='.'
2018-07-11 16:13:15 Trying paths: ['/home/jamiro/.docker/config.json', '/home/jamiro/.dockercfg']
2018-07-11 16:13:15 No config file found
2018-07-11 16:13:15 Trying paths: ['/home/jamiro/.docker/config.json', '/home/jamiro/.dockercfg']
2018-07-11 16:13:15 No config file found
Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

To my understanding, I do have docker installed, as performing docker --version results in the following output:

Docker version 18.03.1-ce, build 9ee9f40

Does anyone one have an idea why sam can't find docker?

like image 662
J. Leander Avatar asked Jul 11 '18 14:07

J. Leander


People also ask

Does AWS SAM need Docker?

AWS SAM provides a local environment that's similar to AWS Lambda to use as a Docker container. You can use this container to build, test, and debug your serverless applications. To run serverless projects and functions locally with the AWS SAM CLI, you must have Docker installed and working.

Can I run Docker on AWS Lambda?

A Lambda container image is a package that includes the Lambda Runtime API, necessary dependencies, an operating system, and function handlers required to run Docker containers in AWS Lambda. These packages allow development teams to deploy and execute arbitrary code and libraries into the Lambda runtime.

What does Sam build -- Use container do?

The sam build command processes your AWS SAM template file, application code, and any applicable language-specific files and dependencies. The command also copies build artifacts in the format and location expected for subsequent steps in your workflow.


2 Answers

Follow these steps:

  1. Delete the ~/.docker directory
  2. Create the "docker" group
  3. Add my user to the "docker" group
  4. Logout and back in again
  5. Restart the "docker" daemon.

More info in the Docker postinstall instructions

like image 181
juanlumn Avatar answered Nov 14 '22 19:11

juanlumn


I had an older version of docker installed. Although docker was working fine, sam could not detect it properly.

sam local start-api --debug

docker.errors.APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.35, server API version: 1.24)") Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

I removed the old version and re-installed the docker.io package (under Ubuntu). Then I started the docker daemon and the issue was fixed.

like image 36
andrei Avatar answered Nov 14 '22 17:11

andrei