bluprince13 / sam-app-connect-to-host-localhost

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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sam-app-connect-to-host-localhost

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/

Pre-requisites

To use the SAM CLI, you need the following tools.

Install dependencies

pip3 install -r requirements.txt

Deploy a python server locally on your machine

flask --app hello run

Use the SAM CLI to build and run a lambda locally

Build first time

sam build --use-container

Build and run

sam build && sam local start-api

About

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.


Languages

Language:Python 100.0%