👻

sam localでRunning AWS SAM projects locally requires Docker.

2023/01/12に公開

タイトル

文字数制限で入りきらなかったけども、本当のタイトルは「macでsam local start-apiでError: Running AWS SAM projects locally requires Docker. Have you got it installed and running?となった場合の対応」

前提

  • machine : mac intel
  • os : 13.1(22C65)
  • docker : Docker version 20.10.21, build baeda1f
  • sam : SAM CLI, version 1.69.0

Error内容

dockerは稼働しているが、なぜか「お前docker動いているか?」と言われる

% sam local start-api
Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?
% docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

対応内容

https://github.com/aws/aws-sam-cli/issues/575

  • mac上で"docker"groupを作る
  • 利用ユーザーを作成した"docker"groupに追加
  • macを再起動

対応後

動いたよ!

% sam local invoke
Invoking app.lambda_handler (python3.9)
Image was not found.
Removing rapid images for repo public.ecr.aws/sam/emulation-python3.9
Building image........................
Skip pulling image and use local one: public.ecr.aws/sam/emulation-python3.9:rapid-1.69.0-x86_64.

Mounting /Users/shigeruoda/Documents/GitHub/pj01/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 357b893a-2cf6-4e71-8c84-0dd4e3520fc2 Version: $LATEST
END RequestId: 357b893a-2cf6-4e71-8c84-0dd4e3520fc2
REPORT RequestId: 357b893a-2cf6-4e71-8c84-0dd4e3520fc2  Init Duration: 0.73 ms  Duration: 318.98 ms     Billed Duration: 319 ms Memory Size: 128 MB     Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}

Discussion