From e5ba53e787818fa23ca7dce3ee83945dd7bf121b Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Thu, 17 Jul 2025 20:18:46 +0000 Subject: [PATCH] save exisiting work --- .../extractor_and_loader/docker/Dockerfile | 25 ++++++++++++++++ .../lambda/extractor_and_loader/docker/app.py | 30 +++++++++++++++++++ .../extractor_and_loader/docker/main.tf | 0 .../lambda/extractor_and_loader/main.tf | 0 .../lambda/extractor_and_loader/provider.tf | 16 ++++++++++ deployment/lambda/lambda_shared/output.tf | 9 ++++++ 6 files changed, 80 insertions(+) create mode 100644 deployment/lambda/extractor_and_loader/docker/Dockerfile create mode 100644 deployment/lambda/extractor_and_loader/docker/app.py create mode 100644 deployment/lambda/extractor_and_loader/docker/main.tf create mode 100644 deployment/lambda/extractor_and_loader/main.tf create mode 100644 deployment/lambda/extractor_and_loader/provider.tf create mode 100644 deployment/lambda/lambda_shared/output.tf diff --git a/deployment/lambda/extractor_and_loader/docker/Dockerfile b/deployment/lambda/extractor_and_loader/docker/Dockerfile new file mode 100644 index 0000000..609981a --- /dev/null +++ b/deployment/lambda/extractor_and_loader/docker/Dockerfile @@ -0,0 +1,25 @@ +FROM public.ecr.aws/lambda/python:3.12 + +# Install Poetry (you could pin a version if you like) +RUN curl -sSL https://install.python-poetry.org | python3 - + +# Add Poetry to PATH +ENV PATH="/root/.local/bin:$PATH" + +# Set working directory +WORKDIR /var/task + +# Copy Poetry files first to leverage Docker layer caching +COPY pyproject.toml poetry.lock README.md ./ +COPY etl/ etl/ + + +# Install dependencies into /var/task +RUN poetry config virtualenvs.create false \ + && poetry install --only main --no-interaction --no-ansi + +# Copy app code +COPY deployment/extractor_and_loader/app.py ./ + +# Set Lambda handler +CMD ["app.handler"] \ No newline at end of file diff --git a/deployment/lambda/extractor_and_loader/docker/app.py b/deployment/lambda/extractor_and_loader/docker/app.py new file mode 100644 index 0000000..4a281ed --- /dev/null +++ b/deployment/lambda/extractor_and_loader/docker/app.py @@ -0,0 +1,30 @@ +""" +A quick example of lambda working a function in python +""" +from etl.read_stuff_from_s3_example import print_hello_from_etl_module + +def handler(event, context): + print("Outside try statment") + print_hello_from_etl_module() + try: + print("show me something.. anything...") + s3_uri = event.get("file_location") + if not s3_uri: + print("failed to get s3_uri") + return { + "statusCode": 400, + "body": "Missing 'file_location' in event" + } + print(f"s3 uri is {s3_uri}") + + return { + "statusCode": 200, + "body": f"s3 uri {s3_uri}" + } + + except Exception as e: + print(f"❌ Error: {e}") + return { + "statusCode": 500, + "body": str(e) + } \ No newline at end of file diff --git a/deployment/lambda/extractor_and_loader/docker/main.tf b/deployment/lambda/extractor_and_loader/docker/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/deployment/lambda/extractor_and_loader/main.tf b/deployment/lambda/extractor_and_loader/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/deployment/lambda/extractor_and_loader/provider.tf b/deployment/lambda/extractor_and_loader/provider.tf new file mode 100644 index 0000000..0997e35 --- /dev/null +++ b/deployment/lambda/extractor_and_loader/provider.tf @@ -0,0 +1,16 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 6.3.0" + } + } + backend "s3" { + bucket = "survey-extractor-tf-state" + region = "eu-west-2" + profile = "domna.dev" # /home/vscode/aws/credentials + key = "env:/dev/extractor_and_loader_lambda.tfstate" + } + + required_version = ">= 1.2.0" +} diff --git a/deployment/lambda/lambda_shared/output.tf b/deployment/lambda/lambda_shared/output.tf new file mode 100644 index 0000000..9d4094d --- /dev/null +++ b/deployment/lambda/lambda_shared/output.tf @@ -0,0 +1,9 @@ +output "lambda_exec_role_arn" { + description = "The ARN of the IAM role used by the Lambda functions" + value = aws_iam_role.lambda_exec_role.arn +} + +output "lambda_exec_role_name" { + description = "The ARN of the IAM role used by the Lambda functions" + value = aws_iam_role.lambda_exec_role.name +}