mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-30 13:10:56 +00:00
lambda tf
This commit is contained in:
parent
383d5ded5f
commit
dd49a9e597
3 changed files with 71 additions and 0 deletions
53
deployment/lambda.tf
Normal file
53
deployment/lambda.tf
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
provider "aws" {
|
||||
region = "us-east-1" # Change if needed
|
||||
}
|
||||
|
||||
resource "aws_sqs_queue" "my_queue" {
|
||||
name = "my-lambda-queue"
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "lambda_exec_role" {
|
||||
name = "lambda-exec-role"
|
||||
|
||||
assume_role_policy = jsonencode({
|
||||
Version = "2012-10-17"
|
||||
Statement = [
|
||||
{
|
||||
Action = "sts:AssumeRole"
|
||||
Effect = "Allow"
|
||||
Principal = {
|
||||
Service = "lambda.amazonaws.com"
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
|
||||
role = aws_iam_role.lambda_exec_role.name
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "sqs_access" {
|
||||
role = aws_iam_role.lambda_exec_role.name
|
||||
policy_arn = "arn:aws:iam::aws:policy/AWSLambdaSQSQueueExecutionRole"
|
||||
}
|
||||
|
||||
resource "aws_ecr_repository" "lambda_repo" {
|
||||
name = "lambda-hello-world"
|
||||
}
|
||||
|
||||
resource "aws_lambda_function" "lambda_docker" {
|
||||
function_name = "docker-hello-world"
|
||||
role = aws_iam_role.lambda_exec_role.arn
|
||||
package_type = "Image"
|
||||
image_uri = "${aws_ecr_repository.lambda_repo.repository_url}:latest"
|
||||
|
||||
timeout = 10
|
||||
}
|
||||
|
||||
resource "aws_lambda_event_source_mapping" "sqs_trigger" {
|
||||
event_source_arn = aws_sqs_queue.my_queue.arn
|
||||
function_name = aws_lambda_function.lambda_docker.arn
|
||||
batch_size = 1
|
||||
}
|
||||
8
deployment/lamda/Dockerfile
Normal file
8
deployment/lamda/Dockerfile
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# AWS Lambda python pacakge
|
||||
FROM public.ecr.aws/lambda/python:3.11
|
||||
|
||||
# Copy function code
|
||||
COPY app.py ./
|
||||
|
||||
# Set the CMD to your handler
|
||||
CMD ["app.handler"]
|
||||
10
deployment/lamda/app.py
Normal file
10
deployment/lamda/app.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
"""
|
||||
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'
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue