5

Trying to port forward dockerized Lambda to my localhost using command:

$ sam local start-api --docker-network host

Error every time trying to access Lambda:

No response from invoke container for FunctionName

Tried also using host.docker.internal & host.docker.local networks with no success.

Any ideas? Workarounds?

MCMatan
  • 8,623
  • 6
  • 46
  • 85
  • Can you pass argument `--debug` and see is there any additional information available? Also, does it work with local Docker (without `--docker-network`)? – xhg Mar 02 '21 at 01:39
  • Nothing there, it seems to be a known open issue of SAM – MCMatan Mar 02 '21 at 08:58

1 Answers1

2

That doesn't seem to work, but using your host computer's IP address does...

Say your host computer's IP address is 192.168.1.111 . You can use that from your Lambda to hit your host

You can make this configurable:

template.yml:

...
Environment:
  Variables:
    ENDPOINT_URL: null

env.json:

{
  "Parameters":{
    "ENDPOINT_URL":"http://192.168.1.111:5000"
  }
}

lambda_function.py:

...
default_sns_endpoint = f'https://sns.{os.environ["AWS_REGION"]}.amazonaws.com'
endpoint_url = os.environ.get("ENDPOINT_URL", "") or default_endpoint

sns = boto3.client("sns", endpoint_url=endpoint_url)
...

start SAM:

sam local invoke --env-vars env.json
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152