example of lambda function

This commit is contained in:
Jun-te Kim 2025-07-15 12:24:14 +00:00
parent 616b6dde9b
commit c220f35252
4 changed files with 8 additions and 23 deletions

View file

@ -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:

View file

@ -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"]

View file

@ -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'
}

View file

@ -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"