-
Docker must be installed and running on your machine.
-
Run docker compose:
# clone the repo then cd into it
cd ~/devel/sn-number-masking
docker compose up
- Create a virtual environment in the project root directory:
# this must match the in serverless.yml
python3.11 -m venv .venv
# activate the virtual environment we just created
source .venv/bin/activate
# Install the required packages with manylinux2014_x86_64 platform to avoid GLIBC errors
pip install -r requirements.txt --platform manylinux2014_x86_64 --only-binary=:all: --target .venv/lib/python3.11/site-packages
- Install the serverless framework and dependencies:
pnpm install -g serverless
pnpm install
- Deploy the stack:
serverless deploy --stage local
- Test the endpoint
curl -X POST http://localhost:4566/restapis/apiid123/local/_user_request_/test -H "Content-Type: application/json" -d '{"real_number": "+16505604560"}' | jq
Notice, we setup a static ID so the URLs don't keep changing:
apiid123
.
If you get errors like No module named 'plivo'
, this is the fix.
Your ./src/__init__.py
should look like this:
import os
import sys
import glob
def is_running_on_localstack():
"""
Determine if the current environment is running on LocalStack.
"""
# Check for LocalStack-specific environment variable
if os.environ.get("LOCALSTACK_HOSTNAME"):
return True
# for hot-reload on
if is_running_on_localstack():
"""
Add the .venv to localstack lambdas for hot-reload.
See https://docs.localstack.cloud/user-guide/lambda-tools/hot-reloading/#hot-reloading-for-python-lambdas
"""
sys.path.insert(0, glob.glob(".venv/lib/python*/site-packages")[0])
For hot reloading to work (very important!), you need to set mountCode: true
. See Hot Reloading | LocalStack Docs.
custom:
localstack:
stages:
- local
lambda:
mountCode: true # <<<