Skip to content

Commit

Permalink
event rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tajewole-moj committed Oct 18, 2023
1 parent 0ba836f commit 5edd770
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
21 changes: 21 additions & 0 deletions terraform/environments/apex/lambda.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "iambackup" {
source = "./module/lambdapolicy"
backup_policy_name = "laa-${local.application_name}-${local.environment}-policy"
tags = merge(
local.tags,
{ Name = "laa-${local.application_name}-${local.environment}-mp" }
Expand All @@ -25,3 +26,23 @@ runtime = local.runtime
{ Name = "laa-${local.application_name}-${local.environment}-mp" }
)
}


resource "aws_cloudwatch_event_rule" "mon_sun" {
name = "${local.application_name}-createSnapshotRule-LWN8E1LNHFJR"
description = "Fires every five minutes"
schedule_expression = "0 2 ? * MON-SUN *"
}

resource "aws_cloudwatch_event_target" "check_mon_sun" {
rule = aws_cloudwatch_event_rule.mon_sun.name
arn = module.lambda_backup.lambda_function
}

resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_mon_sun" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = module.lambda_backup.lambda_function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.mon_sun.arn
}
7 changes: 7 additions & 0 deletions terraform/environments/apex/module/lambda/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "lambda_function" {
value = aws_lambda_function.snapshotDBFunction.*.arn
}

output "lambda_function_name" {
value = aws_lambda_function.snapshotDBFunction.*.function_name
}
6 changes: 3 additions & 3 deletions terraform/environments/apex/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ variable "filename" {
}

variable "function_name" {
type = list(string)
type = list(any)
default = ["snapshotDBFunction","deletesnapshotFunction","connectDBFunction"]
}

variable "handler" {
type = list(string)
type = list(any)
default = ["snapshot/dbsnapshot.handler","deletesnapshots.lambda_handler","ssh/dbconnect.handler"]
}

variable "runtime" {
type = list(string)
type = list(any)
default = [ "nodejs18.x","python3.8","nodejs18.x"]
}

0 comments on commit 5edd770

Please sign in to comment.