diff --git a/backend/pashub_fetcher/handler/Dockerfile b/backend/pashub_fetcher/handler/Dockerfile index a67304ad..1534afdb 100644 --- a/backend/pashub_fetcher/handler/Dockerfile +++ b/backend/pashub_fetcher/handler/Dockerfile @@ -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"] \ No newline at end of file +CMD ["backend.pashub_fetcher.handler.handler.handler"] \ No newline at end of file diff --git a/backend/pashub_fetcher/handler/handler.py b/backend/pashub_fetcher/handler/handler.py index 8fd7e175..00fbd6b5 100644 --- a/backend/pashub_fetcher/handler/handler.py +++ b/backend/pashub_fetcher/handler/handler.py @@ -7,4 +7,4 @@ logger = setup_logger() def handler(event: Mapping[str, Any], context: Any) -> None: - logger.info("Recevied message") + logger.info("Received message") diff --git a/backend/docker-compose-local-lambdas.yml b/backend/pashub_fetcher/local_handler/docker-compose.yml similarity index 50% rename from backend/docker-compose-local-lambdas.yml rename to backend/pashub_fetcher/local_handler/docker-compose.yml index 50e9193b..0ee53283 100644 --- a/backend/docker-compose-local-lambdas.yml +++ b/backend/pashub_fetcher/local_handler/docker-compose.yml @@ -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 \ No newline at end of file + - ../../../.env \ No newline at end of file diff --git a/backend/pashub_fetcher/local_handler/invoke_local_lambda.py b/backend/pashub_fetcher/local_handler/invoke_local_lambda.py new file mode 100644 index 00000000..463ef9d8 --- /dev/null +++ b/backend/pashub_fetcher/local_handler/invoke_local_lambda.py @@ -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)