mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-30 13:10:56 +00:00
lambda example completed
This commit is contained in:
parent
0f66ff70d9
commit
0be7ef6c89
4 changed files with 33 additions and 7 deletions
3
deployment/lambda/lambda_example/docker/output.tf
Normal file
3
deployment/lambda/lambda_example/docker/output.tf
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
output "ecr_repo_url" {
|
||||
value = aws_ecr_repository.lambda_example.repository_url
|
||||
}
|
||||
|
|
@ -1,10 +1,18 @@
|
|||
# Reference existing IAM role
|
||||
data "aws_iam_role" "lambda_exec_role" {
|
||||
name = "lambda-exec-role"
|
||||
}
|
||||
|
||||
# Reference existing ECR repository
|
||||
data "aws_ecr_repository" "lambda_example" {
|
||||
name = "lambda_example"
|
||||
}
|
||||
|
||||
# SQS queue for lambda_example
|
||||
resource "aws_sqs_queue" "lambda_example_queue" {
|
||||
name = "lambda-example-queue"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Custom IAM policy specific to lambda_example
|
||||
resource "aws_iam_policy" "lambda_example_policy" {
|
||||
name = "lambda-example-policy"
|
||||
|
|
@ -28,7 +36,7 @@ resource "aws_iam_policy" "lambda_example_policy" {
|
|||
"ecr:BatchGetImage",
|
||||
"ecr:BatchCheckLayerAvailability"
|
||||
],
|
||||
Resource = aws_ecr_repository.lambda_example.arn
|
||||
Resource = data.aws_ecr_repository.lambda_example.arn
|
||||
},
|
||||
{
|
||||
Effect = "Allow",
|
||||
|
|
@ -40,16 +48,16 @@ resource "aws_iam_policy" "lambda_example_policy" {
|
|||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "lambda_example_policy_attach" {
|
||||
role = aws_iam_role.lambda_exec_role.name
|
||||
role = data.aws_iam_role.lambda_exec_role.name
|
||||
policy_arn = aws_iam_policy.lambda_example_policy.arn
|
||||
}
|
||||
|
||||
# Lambda function
|
||||
resource "aws_lambda_function" "lambda_example" {
|
||||
function_name = "lambda-example"
|
||||
role = aws_iam_role.lambda_exec_role.arn
|
||||
role = data.aws_iam_role.lambda_exec_role.arn
|
||||
package_type = "Image"
|
||||
image_uri = "${aws_ecr_repository.lambda_example.repository_url}:latest"
|
||||
image_uri = "${data.aws_ecr_repository.lambda_example.repository_url}:latest"
|
||||
timeout = 10
|
||||
}
|
||||
|
||||
|
|
@ -59,4 +67,3 @@ resource "aws_lambda_event_source_mapping" "lambda_example_trigger" {
|
|||
function_name = aws_lambda_function.lambda_example.arn
|
||||
batch_size = 1
|
||||
}
|
||||
|
||||
|
|
|
|||
0
deployment/lambda/lambda_example/main.tf
Normal file
0
deployment/lambda/lambda_example/main.tf
Normal file
16
deployment/lambda/lambda_example/provider.tf
Normal file
16
deployment/lambda/lambda_example/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/eachlambda/lambda_example.tfstate"
|
||||
}
|
||||
|
||||
required_version = ">= 1.2.0"
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue