added extractor and loader

This commit is contained in:
Jun-te Kim 2025-07-18 10:10:16 +00:00
parent cf2f4584c0
commit 9a914a6e97
5 changed files with 47 additions and 11 deletions

View file

@ -0,0 +1,26 @@
# ECR repo
resource "aws_ecr_repository" "extractor_and_loader" {
name = "extractor_and_loader"
}
# ECR policy to allow Lambda access
resource "aws_ecr_repository_policy" "extractor_loader_ecr_access" {
repository = aws_ecr_repository.extractor_and_loader.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/extractor_and_loader.tfstate"
}
required_version = ">= 1.2.0"
}

View file

@ -37,7 +37,7 @@ resource "aws_iam_policy" "extractor_loader_policy" {
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability"
],
Resource = data.aws_ecr_repository.lambda_example.arn
Resource = data.aws_ecr_repository.extractor_and_loader.arn
},
{
Effect = "Allow",
@ -56,9 +56,9 @@ resource "aws_iam_role_policy_attachment" "extractor_loader_policy_attach" {
# Lambda function
resource "aws_lambda_function" "extractor_and_loader" {
function_name = "extractor-and-loader"
role = aws_iam_role.lambda_exec_role.arn
role = data.aws_iam_role.lambda_exec_role.arn
package_type = "Image"
mage_uri = "${data.aws_ecr_repository.extractor_and_loader.repository_url}:latest"
image_uri = "${data.aws_ecr_repository.extractor_and_loader.repository_url}:latest"
timeout = 30
}

View file

@ -9,7 +9,7 @@ terraform {
bucket = "survey-extractor-tf-state"
region = "eu-west-2"
profile = "domna.dev" # /home/vscode/aws/credentials
key = "env:/dev/extractor_and_loader_lambda.tfstate"
key = "env:/dev/lambda/eachlambda/extractor_and_loader_lambda.tfstate"
}
required_version = ">= 1.2.0"

View file

@ -4,13 +4,7 @@ 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}")
print("Printing from lambda example")
return {
"statusCode": 200,