This is a minimal working example to figure out how to let a lambda running locally via SAM CLI can call a server running on the host machine's localhost.
Referred to on StackOverflow question: How to connect a lambda to a database accessible locally on Mac's localhost when using sam
Contents:
./hello.py
- A simple Python server that can be run on the host machine.
- Accessible on
http://127.0.0.1:5000/
./hello_world/app.py
:- A Lambda function that calls the server running on the host machine.
- When deployed with SAM CLI, this is available on
http://127.0.0.1:3000/
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Python 3 installed
- Docker - Install Docker community edition
pip3 install -r requirements.txt
flask --app hello run
sam build --use-container
sam build && sam local start-api