Added lambda auto config

This commit is contained in:
2024-04-25 12:54:31 +02:00
parent 2cdc051191
commit 0bc1265b68
4 changed files with 241 additions and 31 deletions

View File

@@ -140,14 +140,20 @@ resource "aws_iam_role" "iam_for_lambda" {
data "archive_file" "lambda_standout_code" {
type = "zip"
source_file = "./lambda_redirect/lambda_redirect.py"
output_path = "./lambda_redirect/standout_lambda_function.zip"
source_dir = "./lambda_redirect"
output_path = "./lambda_zip/standout_lambda_redirect.zip"
}
data "archive_file" "lambda_standout_config_code" {
type = "zip"
source_dir = "./lambda_config"
output_path = "./lambda_zip/standout_lambda_config.zip"
}
resource "aws_lambda_function" "lambda_standout_redirect" {
# If the file is not in the current working directory you will need to include a
# path.module in the filename.
filename = "./lambda_redirect/standout_lambda_function.zip"
filename = "./lambda_zip/standout_lambda_redirect.zip"
function_name = "standout-redirect"
role = aws_iam_role.iam_for_lambda.arn
handler = "lambda_redirect.lambda_handler"
@@ -166,6 +172,47 @@ resource "aws_lambda_function" "lambda_standout_redirect" {
}
}
resource "aws_lambda_function" "lambda_standout_config" {
# If the file is not in the current working directory you will need to include a
# path.module in the filename.
filename = "./lambda_zip/standout_lambda_config.zip"
function_name = "standout-config"
role = aws_iam_role.iam_for_lambda.arn
handler = "lambda_config.lambda_handler"
source_code_hash = data.archive_file.lambda_standout_code.output_base64sha256
runtime = "python3.12"
timeout = 10
environment {
variables = {
BUCKET_CONFIG = aws_s3_bucket.s3_standout_config.bucket,
BUCKET_DATA = aws_s3_bucket.s3_standout.bucket
}
}
}
# Add S3 trigger to config lambda
resource "aws_lambda_permission" "lambda_config_s3_trigger_allow" {
statement_id = "AllowExecutionFromS3Bucket"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda_standout_config.arn
principal = "s3.amazonaws.com"
source_arn = aws_s3_bucket.s3_standout.arn
}
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = aws_s3_bucket.s3_standout.id
lambda_function {
lambda_function_arn = aws_lambda_function.lambda_standout_config.arn
events = ["s3:ObjectCreated:*", "s3:ObjectRemoved:*"]
}
}
# create API gateway for lambda triger and connect
resource "aws_apigatewayv2_api" "api_standout_gateway" {
name = "standout-api"