2

We are developing locally using SAM Local to invoke a Lambda in an API Gateway. SAM Local does this using a Docker container (setup as close to the Lambda node runtime as possible). We want this Lambda to access some data in an API Mocking service in the shape of some Node express servers running in another container (this could also just be run locally too if needed). Both containers are in a user-created Docker bridge network created as follows:

docker network create sam-demo

The API mocking service is run and added to the bridge network:

docker run --network sam-demo --name mock -d -P mock:latest

The Lambda is invoked in debug mode and added to the bridge network:

sam local start-api -t template.json -d 9229 --docker-network sam-demo

Inspecting the bridge network reveals both the SAM local lambda (wizardly_knuth) and the mocks are there:

        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "5ebfa4295a56e4df840676a2e214891543fd4e8cb271ed70ddd67946ab451119": {
                "Name": "wizardly_knuth",
                "EndpointID": "xxx",
                "MacAddress": "02:42:ac:14:00:03",
                "IPv4Address": "172.20.0.3/16",
                "IPv6Address": ""
            },
            "d735c9aa840e4ce7180444cf168cd6b68451c9ca29ba87b7cb23edff11abea7b": {
                "Name": "mock",
                "EndpointID": "xxx",
                "MacAddress": "02:42:ac:14:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }

Now, what should the URL be for the Lambda to hit the mock? According to Docker docs it should be the IPv4Address of the mock container i.e. http://172.20.0.2 but I am not sure what port or how to find what port?

I can exec into the mock and ping the SAM Local container successfully BUT I can't do the same from the SAM Local container as the shell doesn't have ping, curl, nc or anything installed.

I can't hit the Mock container directly from my machine as it is a Mac and I believe there are issues with doing so.

Any advice or next steps are greatly appreciated.

Much thanks,

Sam

SamBrick
  • 681
  • 1
  • 8
  • 33

1 Answers1

4

UPDATE


In the end I gave up on this approach as I could not figure out what the URL for the Lambda should be to hit the mock within the Docker Bridge network.

The alternative approach was to actually just hit the mock Docker container directly from the Lambda using this URL (the mock container is exposing port 3002):-

http://docker.for.mac.localhost:3002/

Hope this might help somebody out.... please let me know if anyone solves the bridge network issue I originally posted about.

Thanks,

Sam

SamBrick
  • 681
  • 1
  • 8
  • 33
  • 1
    you could have used `--docker-network host`, but that is bad when you try to run multiple lambda in parallel – Matteo Nov 19 '20 at 06:45