0

I am learning AWS Lambda. Unfortunately, I can't install SAM-TOOLKIT (sam-cli) on my host computer MAC, but I have Docker installed.

Now, I work inside Docker flawlessly. I have started the docker-container (from base image of Linux Ubuntu) and have installed all necessary softwares inside the Container like "sudo", "JDK", "maven", "vim", "aws-cli", "sam-cli", etc.

I am perfectly able to run and execute "sam build" && "sam deploy" commands inside my docker-container, but when I try to execute the command like sam local invoke HelloWorldFunction/ --event events/testEventWithOneParameter.json I am getting below error :-

Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?

How do I now solve this problem of having Docker inside Docker ? Your early response shall be highly appreciated ?

Aditya Goel
  • 201
  • 1
  • 15
  • can you post your dockerfile or link where we can check dependency? seems like it need docker runtime as well – Adiii Jan 18 '22 at 05:46
  • or better to try the aws docker image instead of baking own one https://hub.docker.com/r/amazon/aws-sam-cli-build-image-provided – Adiii Jan 18 '22 at 05:51
  • @Adiii That's fine. Docker Image is not an issue Adi and neither I am using any Dockerfile. For now, this question is solved. Can you help me with this question dear : https://stackoverflow.com/questions/70810264/facing-challenge-in-testing-lambda-locally-inside-docker – Aditya Goel Jan 22 '22 at 05:35

1 Answers1

1

You have few options here. Docker in Docker is common use-case these days and there are more than one solutions to achieve this. You can use docker.sock or dind to run docker command inside container or create docker image in a container itself.

Reference walkthrough: https://devopscube.com/run-docker-in-docker/

Hussain Mansoor
  • 2,934
  • 2
  • 27
  • 40
  • Dear @Hussain Thanks for responding. I have been able to resolve this error with below command : sam local invoke HelloWorldFunction --event events/testEventWithOneParameter.json But now I am getting below error : docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Mounts denied: \nThe path /adityaLearningLambda/.aws-sam/build/HelloWorldFunction is not shared from the host and is not known to Docker.\nYou can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.\nSee https://docs.docker.com/docker-for-mac for more info.'") – Aditya Goel Jan 20 '22 at 10:38
  • Editing the question for better clarity. – Aditya Goel Jan 20 '22 at 10:39
  • Instead of editing the same question. Please open a new question for different issue. It reduces the complexity of the question for future readers. – Hussain Mansoor Jan 20 '22 at 10:51
  • Alright point noted @Hussain. Thanks for answering this question. I have accepted the answer. I have opened an another question for other error : https://stackoverflow.com/questions/70810264/facing-challenge-in-testing-lambda-locally-inside-docker Would appreciate, if you can have a look at the same. – Aditya Goel Jan 22 '22 at 05:32