From 263003e30a8c4ca3e5984faa430b9288ee6466a8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 May 2025 16:49:48 -0400 Subject: [PATCH] Initialize Dockerfile and app.py for Lambda function setup --- Dockerfile | 14 ++++++++++++++ app.py | 11 +++++++++++ packer.pkr.hcl | 7 ++++++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 app.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5119464 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM public.ecr.aws/lambda/python:3.11 + +# Copy requirements first to leverage Docker cache +COPY requirements.txt /tmp/ +RUN pip install --no-cache-dir -r /tmp/requirements.txt -t ${LAMBDA_TASK_ROOT} + +# Copy the template_automation package +COPY template_automation/ ${LAMBDA_TASK_ROOT}/template_automation/ + +# Copy the root app.py file (this is essential for AWS Lambda to find the handler) +COPY app.py ${LAMBDA_TASK_ROOT}/ + +# Ensure the Lambda handler is correctly set +CMD [ "app.lambda_handler" ] diff --git a/app.py b/app.py new file mode 100644 index 0000000..98f2de4 --- /dev/null +++ b/app.py @@ -0,0 +1,11 @@ +""" +Lambda function entrypoint that imports the handler from the template_automation package. + +This file resolves the 'attempted relative import with no known parent package' +error by placing an entrypoint at the root level of the Lambda package. +""" + +from template_automation.app import lambda_handler + +# Re-export the lambda_handler function for Lambda runtime to find it +__all__ = ['lambda_handler'] diff --git a/packer.pkr.hcl b/packer.pkr.hcl index 8ceddc9..9f07129 100644 --- a/packer.pkr.hcl +++ b/packer.pkr.hcl @@ -34,7 +34,12 @@ build { provisioner "file" { source = "./template_automation/" - destination = "/var/task" + destination = "/var/task/template_automation/" + } + + provisioner "file" { + source = "./app.py" + destination = "/var/task/app.py" } provisioner "shell" {