Skip to content

Commit

Permalink
Initialize Dockerfile and app.py for Lambda function setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 2, 2025
1 parent 48ad606 commit 263003e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
11 changes: 11 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -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']
7 changes: 6 additions & 1 deletion packer.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 263003e

Please sign in to comment.