set up local lambda runner and invoker

This commit is contained in:
Daniel Roth 2026-03-19 16:22:53 +00:00
parent 8a17ea7265
commit 142024550e
4 changed files with 42 additions and 5 deletions

View file

@ -1,5 +1,12 @@
FROM mcr.microsoft.com/playwright/python:v1.42.0
# Install AWS Lambda RIE
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie
RUN chmod +x /usr/local/bin/aws-lambda-rie
# Install Lambda runtime client
RUN pip install awslambdaric
# Set working directory (Lambda task root)
WORKDIR /var/task
@ -8,9 +15,13 @@ COPY backend/.env.test backend/.env
COPY utils/ utils/
COPY backend/pashub_fetcher/ backend/pashub_fetcher/
# Lambda entrypoint
ENTRYPOINT ["/usr/local/bin/aws-lambda-rie", "python", "-m", "awslambdaric"]
# -----------------------------
# Lambda handler
# -----------------------------
# CMD ["backend/pashub_fetcher/handler/handler.handler"]
# For local running
CMD ["python", "-m", "backend.pashub_fetcher.handler.handler"]
CMD ["backend.pashub_fetcher.handler.handler.handler"]

View file

@ -7,4 +7,4 @@ logger = setup_logger()
def handler(event: Mapping[str, Any], context: Any) -> None:
logger.info("Recevied message")
logger.info("Received message")

View file

@ -3,9 +3,9 @@ version: "3.9"
services:
categorisation-lambda:
build:
context: ../
dockerfile: backend/categorisation/handler/Dockerfile
context: ../../../
dockerfile: backend/pashub_fetcher/handler/Dockerfile
ports:
- "9000:8080"
env_file:
- ../.env
- ../../../.env

View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import json
import requests
HOST = "localhost"
PORT = "9000"
LAMBDA_URL = f"http://{HOST}:{PORT}/2015-03-31/functions/function/invocations"
payload = {
"Records": [
{
"body": json.dumps(
{
"uprn": 123456,
}
)
}
]
}
response = requests.post(LAMBDA_URL, json=payload)
print("Status code:", response.status_code)
print("Response:")
print(response.text)