From c220f35252c1de6e3b251452b0080378d7a042cf Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Tue, 15 Jul 2025 12:24:14 +0000 Subject: [PATCH] example of lambda function --- .github/workflows/push_docker_image_to_ecr.yml | 4 ++-- deployment/lambda/Dockerfile | 8 -------- deployment/lambda/app.py | 11 ----------- deployment/{lambda.tf => lambda_example.tf} | 8 ++++++-- 4 files changed, 8 insertions(+), 23 deletions(-) delete mode 100644 deployment/lambda/Dockerfile delete mode 100644 deployment/lambda/app.py rename deployment/{lambda.tf => lambda_example.tf} (91%) diff --git a/.github/workflows/push_docker_image_to_ecr.yml b/.github/workflows/push_docker_image_to_ecr.yml index 53a640f..e6722cd 100644 --- a/.github/workflows/push_docker_image_to_ecr.yml +++ b/.github/workflows/push_docker_image_to_ecr.yml @@ -1,4 +1,4 @@ -name: Build and Push Docker to ECR +name: Build and Push Docker Image to ECR lambda example on: push: @@ -6,7 +6,7 @@ on: env: AWS_REGION: eu-west-2 - ECR_REPOSITORY: survey_extractor + ECR_REPOSITORY: lambda_example jobs: build-and-push-to-elastic-container-registry: diff --git a/deployment/lambda/Dockerfile b/deployment/lambda/Dockerfile deleted file mode 100644 index b27e4ff..0000000 --- a/deployment/lambda/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -# AWS Lambda python pacakge -FROM public.ecr.aws/lambda/python:3.11 - -# Copy function code -COPY deployment/lambda/app.py ./ - -# Set the CMD to your handler -CMD ["app.handler"] \ No newline at end of file diff --git a/deployment/lambda/app.py b/deployment/lambda/app.py deleted file mode 100644 index 05e2693..0000000 --- a/deployment/lambda/app.py +++ /dev/null @@ -1,11 +0,0 @@ -""" -A quick example of lambda working a function in python -""" - -def handler(event, context): - print("Hello from Python function. This shold be running from a dockerfile env and executed on a aws lambda!") - return { - 'statusCode': 200, - 'body': 'Hello World' - } - diff --git a/deployment/lambda.tf b/deployment/lambda_example.tf similarity index 91% rename from deployment/lambda.tf rename to deployment/lambda_example.tf index 4b56763..0748af4 100644 --- a/deployment/lambda.tf +++ b/deployment/lambda_example.tf @@ -1,3 +1,7 @@ +# This is an example file to setup a lamda function with a sqs and cloudwatch. +# Please us this as a template for future lambda. +# Be sure to push the image you are using to ECR or it won't deploy properly + # Create an SQS queue that will trigger the Lambda resource "aws_sqs_queue" "my_queue" { name = "my-lambda-queue" @@ -5,7 +9,7 @@ resource "aws_sqs_queue" "my_queue" { # Create an ECR repository to store the Docker image for the Lambda function resource "aws_ecr_repository" "lambda_repo" { - name = "survey_extractor" + name = "lambda_example" } # IAM role that the Lambda function will assume @@ -79,7 +83,7 @@ resource "aws_iam_role_policy_attachment" "lambda_custom_policy_attach" { # Define the Lambda function using a Docker image from ECR resource "aws_lambda_function" "lambda_docker" { - function_name = "docker-hello-world" + function_name = "docker-hello-world-python-example" role = aws_iam_role.lambda_exec_role.arn package_type = "Image" image_uri = "${aws_ecr_repository.lambda_repo.repository_url}:latest"