Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/gp-news/usw2dev/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,30 @@ resource "aws_lambda_function" "gp_news_lambda" {

architectures = ["x86_64"]
}

resource "aws_cloudwatch_event_rule" "gp_news_periodic" {
count = length(var.schedule_daily_utc_time)

name = "gp-news-scraper-periodic-trigger-${count.index}"
description = "Trigger GP News scraper lambda daily at ${var.schedule_daily_utc_time[count.index]} UTC"
schedule_expression = "cron(${split(":", var.schedule_daily_utc_time[count.index])[1]} ${split(":", var.schedule_daily_utc_time[count.index])[0]} * * ? *)"
Comment on lines +21 to +23
}

resource "aws_cloudwatch_event_target" "gp_news_scraper_lambda" {
count = length(var.schedule_daily_utc_time)

rule = aws_cloudwatch_event_rule.gp_news_periodic[count.index].name
target_id = "GPNewsScraperLambda-${count.index}"
arn = aws_lambda_function.gp_news_lambda.arn
}

resource "aws_lambda_permission" "allow_eventbridge" {
count = length(var.schedule_daily_utc_time)

statement_id = "AllowExecutionFromEventBridge-${count.index}"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.gp_news_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.gp_news_periodic[count.index].arn
Comment on lines +19 to +41
}

1 change: 1 addition & 0 deletions apps/gp-news/usw2dev/terraform.auto.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
env_name = "usw2dev"
schedule_daily_utc_time = ["00:00", "15:00"]
6 changes: 6 additions & 0 deletions apps/gp-news/usw2dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ variable "num_versions_to_keep" {
description = "Number of versions to keep"
type = number
default = 3
}

variable "schedule_daily_utc_time" {
description = "The UTC time to schedule the daily scraper (in HH:MM format)"
Comment on lines +30 to +31
type = list(string)
default = ["00:00"]
}
Loading