0

The command sam local start-lambda spins up a server inside a Docker container that emulates an AWS Lambda function:

$ sam local start-lambda
Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template through the endpoint.
2020-05-29 12:32:13  * Running on http://127.0.0.1:3001/ (Press CTRL+C to quit)
Fetching lambci/lambda:java8 Docker container image......
Mounting /private/var/folders/p_/0lzsyjqd64j3qynmw8sdmf2ws82gz7/T/tmp19t_696o as /var/task:ro,delegated inside runtime container

I wrote a simple Node.js server that hits this endpoint.

Now, i'd like to package both up (i.e. one would run docker start and both the node.js server & sam local start-lambda would start running), but i'm not sure how to do this.

Can I write a Dockerfile that somehow links these two endpoints?

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130

1 Answers1

2

You can use Docker Compose to do that. https://docs.docker.com/compose/

You would create a service for lambda, and one for node and then configure each accordingly exposing the desired ports, etc., depending on exactly how you want to use them.

JeremyM4n
  • 750
  • 5
  • 10
  • docker compose would create two containers, right? but `sam local start-lambda` already spins up a container... – Maria Ines Parnisari May 29 '20 at 21:05
  • Well, if you do it using Docker Compose then instead of starting lambda with sam, you would need to create the lambda service in Docker-compose, either using an existing build file for lambda, or creating one. Here's an article I found doing something similar: https://cbax.me/posts/2019/03/aws-sam-cli-inside-docker-compose/. Hope that helps. – JeremyM4n May 30 '20 at 00:20