-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
115 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
data "archive_file" "lambda" { | ||
type = "zip" | ||
source_dir = "${path.module}/lambda/" | ||
output_path = "${path.module}/lambda.zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
resource "aws_iam_role" "lambda_execution_role" { | ||
name = "lambda_execution_role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = "sts:AssumeRole" | ||
Effect = "Allow" | ||
Principal = { | ||
Service = "lambda.amazonaws.com" | ||
} | ||
}, | ||
] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
data "archive_file" "lambda_zip" { | ||
type = "zip" | ||
source_file = "./lambda/main.py" | ||
output_path = "./lambda.zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# resource "aws_cloudwatch_event_bus" "trigger" { | ||
# name = "trigger-event-bridge" | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
resource "aws_cloudwatch_event_bus" "trigger" { | ||
name = "trigger-event-bridge" | ||
} | ||
|
||
data "archive_file" "lambda_zip" { | ||
type = "zip" | ||
source_file = "./lambda/main.py" | ||
output_path = "./lambda/lambda.zip" | ||
} | ||
resource "aws_iam_role" "lambda_execution_role" { | ||
name = "lambda_execution_role" | ||
|
||
# IAM Role for Lambda | ||
resource "aws_iam_role" "lambda_role" { | ||
name = "lambda_role" | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = "sts:AssumeRole" | ||
Action = "sts:AssumeRole" | ||
Effect = "Allow" | ||
Principal = { | ||
Service = "lambda.amazonaws.com" | ||
} | ||
Effect = "Allow" | ||
Sid = "" | ||
}, | ||
] | ||
}) | ||
} | ||
|
||
# Lambda Function | ||
resource "aws_lambda_function" "my_lambda" { | ||
function_name = "event-bridge-integration" | ||
|
||
# Use the zip file created by archive_file | ||
filename = data.archive_file.lambda_zip.output_path | ||
|
||
resource "aws_iam_policy" "trigger_event_bus_policy" { | ||
name = "trigger-event-bus" | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "lambda_s3_policy_attachment" { | ||
role = aws_iam_role.lambda_execution_role.name | ||
policy_arn = aws_iam_policy.trigger_event_bus_policy.arn | ||
} | ||
|
||
|
||
resource "aws_lambda_function" "trigger-event-bus" { | ||
function_name = "trigger-event-bus" | ||
filename = "lambda.zip" | ||
source_code_hash = data.archive_file.lambda_zip.output_base64sha256 | ||
|
||
role = aws_iam_role.lambda_role.arn | ||
handler = "main.lambda_handler" # Ensure this matches the function in main.py | ||
runtime = "python3.10" # Or another Python runtime version | ||
|
||
memory_size = 128 | ||
timeout = 10 | ||
handler = "main.lambda_handler" | ||
runtime = "python3.10" # Adjust as per your runtime | ||
role = aws_iam_role.lambda_execution_role.arn | ||
timeout = 30 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
resource "aws_iam_policy" "lambda_s3_access_policy" { | ||
name = "lambda_s3_access_policy" | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
] | ||
Effect = "Allow" | ||
Resource = "arn:aws:logs:*:*:*" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "lambda_s3_policy_attachment" { | ||
role = aws_iam_role.lambda_execution_role.name | ||
policy_arn = aws_iam_policy.lambda_s3_access_policy.arn | ||
} | ||
|
||
|
||
# Step 4: Create the Lambda function (assuming the Lambda ZIP package is uploaded) | ||
resource "aws_lambda_function" "hello-world" { | ||
function_name = "hello-world" | ||
filename = "lambda.zip" | ||
source_code_hash = data.archive_file.lambda.output_base64sha256 | ||
handler = "main.lambda_handler" | ||
runtime = "python3.10" # Adjust as per your runtime | ||
role = aws_iam_role.lambda_execution_role.arn | ||
timeout = 30 | ||
environment { | ||
variables = { | ||
DB_INSTANCE_ID = aws_rds_cluster.primary.id | ||
SNS_TOPIC_ARN = aws_sns_topic.notify.arn | ||
SECRET_NAME = aws_rds_cluster.primary.master_user_secret[0].secret_arn | ||
SUBNET_GROUP_NAME = aws_db_subnet_group.all.name | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters