added docker for lambda example

This commit is contained in:
Jun-te Kim 2025-07-17 15:12:43 +00:00
parent 70a81feb0c
commit 8948e64e13
5 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# AWS Lambda python pacakge
FROM public.ecr.aws/lambda/python:3.11
# Copy function code
COPY deployment/lambda_example/app.py ./
# Set the CMD to your handler
CMD ["app.handler"]

View file

@ -0,0 +1,25 @@
"""
A quick example of lambda working a function in python
"""
def handler(event, context):
try:
s3_uri = event.get("file_location")
if not 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)
}

View file

@ -0,0 +1,25 @@
# ECR repo for lambda_example
resource "aws_ecr_repository" "lambda_example" {
name = "lambda_example"
}
# ECR policy to allow Lambda access
resource "aws_ecr_repository_policy" "lambda_example_ecr_access" {
repository = aws_ecr_repository.lambda_example.name
policy = jsonencode({
Version = "2008-10-17",
Statement = [{
Sid = "AllowLambdaPull",
Effect = "Allow",
Principal = {
Service = "lambda.amazonaws.com"
},
Action = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability"
]
}]
})
}

View file

@ -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/lambda/ecr/lambda_example_ecr.tfstate"
}
required_version = ">= 1.2.0"
}