Running AWS SAM projects locally get error
Asked Answered
H

10

37

I am trying to run an AWS Lambda project locally on Ubuntu. When I run the project with AWS SAM Local it shows me this error: Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

Harappa answered 11/6, 2018 at 6:8 Comment(0)
L
35

Another cause for this is this recent issue within Docker for Mac.

A quick workaround, as specified in the issue itself, is to run SAM with:

$ DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local start-api

You don't need to run SAM as root.

Lawerencelawes answered 17/1, 2023 at 16:20 Comment(3)
I have Docker Desktop installed on Linux. This worked with a slight modification, since docker.sock lives under ~/.docker/desktop.Dodds
This worked for me 22/3/23 on a Mac with up-to-date docker installed and available on the CL.Mausoleum
Docker Desktop -> Go to the Dashboard -> Settings -> Advanced -> Allow the default Docker socket to be used (requires password). No longer need to set DOCKER_HOST env var.Bounds
F
16

This solved it for me on Mac:

  1. Click the settings "cog" icon in the top right
  2. Open the "Advanced" section
  3. Tick "Allow the default Docker socket to be used"
  4. Click the "Apply and restart" button

enter image description here

Federal answered 2/2 at 10:48 Comment(2)
This resolved the issue. It needed to be on top.Rumph
This is correct answer.Gauze
H
15

I had trouble installing it on Fedora.

When I followed the Docker postinstall instructions I managed to get past this issue.

https://docs.docker.com/install/linux/linux-postinstall/

I had to:

  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.

I was then able to run the command:

sam local start-api
Homogenetic answered 2/7, 2018 at 14:3 Comment(3)
In Ubuntu 18 I just needed to add my user in the "docker" group (It was already created) and that was allSuit
Please do not forget to reboot afterward!Duck
This is the solution in Ubuntu 22. I think it works because it allows sam to call docker without using sudo.Devanagari
D
9

I am using colima for docker on mac with intel chip. and faced this error. was able to resolve it by adding DOCKER_HOST in .zshrc file

vi ~/.zshrc

paste export DOCKER_HOST="unix://$HOME/.colima/docker.sock" in the .zshrc file escape :wq

Discomfiture answered 7/2, 2023 at 12:36 Comment(2)
perhaps ~/.zshenvAmarette
In my case, using the Monterey version and the traditional bash shell, I have to modify ~/.bash_profileTucker
S
8

If you want to run local sam-cli, you have first install docker from docker official website then run sudo sam local start-api. Note that sudo is necessary for running local developer with needed privileges.

Sheffy answered 10/9, 2018 at 7:3 Comment(2)
running as root worked for me, do you know why this is necessary?Wilmot
It should have to do with docker having to be invoked with sudo. I think that as of docker version 19 one can run it sudoless, but there are some caveats. All this is just a guess though.Diminished
J
4

This error mostly arises due to lack of admin privilege to use docker. Just add sudo to your command. This will work. eg: sudo sam local start-api --region eu-west-3

Jacobian answered 19/12, 2021 at 9:56 Comment(0)
W
2

We are working on Mac and were seeing same message when using an older version of Docker (1.12.6). Have since updated to a newer (but not latest) version 17.12.0-ce-mac49 and it is now fine.

Watchcase answered 13/8, 2018 at 14:25 Comment(1)
Absolutely. Upgrading Docker, Docker Desktop and (in my case) Rider and AWS Toolkit for Rider helped me solve that issue.Elusive
L
1

For those with Macs and using colima for docker, check two things:

  1. ~/.zshrc or ~/.bashrc have DOCKER_HOST pointed to unix://$HOME/.colima/docker.sock", like export DOCKER_HOST="unix://$HOME/.colima/docker.sock"

  2. Make sure colima is actually running. colima start

Levison answered 30/8, 2023 at 0:57 Comment(0)
Z
0

Go to Docker Desktop, then Settings/Advanced and if the "Allow the default Docker socket to be used (requires password)" option is checked, uncheck it, press "Apply & Restart" button and then check this option again and press "Apply & Restart" button again. It will install /var/run/docker.sock

Zilla answered 17/4 at 6:45 Comment(0)
O
0

Having same issue when working with Docker on macOS ($sam local start-api). But after change setting [Allow the default Docker socket to be used(required password)] in the "Advanced" menu in the desktop, It worked.

Orectic answered 14/6 at 6:21 Comment(1)
Your answer seems unrelated to the question about scaling Quartz scheduler and executor separately. Please ensure your answer addresses the specific question asked.Lawford

© 2022 - 2024 — McMap. All rights reserved.