mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-08 11:17:29 +00:00
added docker for lambda example
This commit is contained in:
parent
70a81feb0c
commit
8948e64e13
5 changed files with 74 additions and 0 deletions
8
deployment/lambda/lambda_example/docker/Dockerfile
Normal file
8
deployment/lambda/lambda_example/docker/Dockerfile
Normal 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"]
|
||||
25
deployment/lambda/lambda_example/docker/app.py
Normal file
25
deployment/lambda/lambda_example/docker/app.py
Normal 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)
|
||||
}
|
||||
25
deployment/lambda/lambda_example/docker/ecr.tf
Normal file
25
deployment/lambda/lambda_example/docker/ecr.tf
Normal 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"
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
0
deployment/lambda/lambda_example/docker/main.tf
Normal file
0
deployment/lambda/lambda_example/docker/main.tf
Normal file
16
deployment/lambda/lambda_example/docker/provider.tf
Normal file
16
deployment/lambda/lambda_example/docker/provider.tf
Normal 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"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue