|
@@ -4,6 +4,18 @@ resource "aws_cloudwatch_log_group" "function" {
|
|
|
tags = merge(var.standard_tags, var.tags)
|
|
|
}
|
|
|
|
|
|
+resource "aws_cloudwatch_log_group" "function_scheduler" {
|
|
|
+ name = "/aws/lambda/${aws_lambda_function.portal_scheduler.function_name}"
|
|
|
+ retention_in_days = 14
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_log_group" "function_customer_sync" {
|
|
|
+ name = "/aws/lambda/${aws_lambda_function.portal_customer_sync.function_name}"
|
|
|
+ retention_in_days = 14
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
###
|
|
|
### Trigger Portal Sync Lambda with Rules and Targets
|
|
|
###
|
|
@@ -172,3 +184,173 @@ resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_lambda_monthly
|
|
|
principal = "events.amazonaws.com"
|
|
|
source_arn = aws_cloudwatch_event_rule.portal_event_monthly_rule.arn
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+###
|
|
|
+### Trigger Portal Scheduler Lambda with Rules and Targets
|
|
|
+###
|
|
|
+
|
|
|
+### Time-based rules for portal sync:
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_quarter_hourly_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-quarter-hourly"
|
|
|
+ description = "Rule for portal scheduler lambda function - every 15 minutes"
|
|
|
+ schedule_expression = "rate(15 minutes)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_half_hourly_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-half-hourly"
|
|
|
+ description = "Rule for portal scheduler lambda function - every 30 minutes"
|
|
|
+ schedule_expression = "rate(30 minutes)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_hourly_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-hourly"
|
|
|
+ description = "Rule for portal scheduler lambda function - every hour"
|
|
|
+ schedule_expression = "rate(1 hour)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_four_hourly_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-four-hourly"
|
|
|
+ description = "Rule for portal scheduler lambda function - every 4 hours"
|
|
|
+ schedule_expression = "rate(4 hours)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_daily_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-daily"
|
|
|
+ description = "Rule for portal scheduler lambda function - every day"
|
|
|
+ schedule_expression = "cron(5 5 * * ? *)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_weekly_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-weekly"
|
|
|
+ description = "Rule for portal scheduler lambda function - every week"
|
|
|
+ schedule_expression = "rate(7 days)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_rule" "portal_scheduler_monthly_rule" {
|
|
|
+ name = "aws-portal-lambda-scheduler-monthly"
|
|
|
+ description = "Rule for portal scheduler lambda function - every month"
|
|
|
+ schedule_expression = "rate(30 days)"
|
|
|
+ is_enabled = var.environment == "test" ? false : true
|
|
|
+ tags = merge(var.standard_tags, var.tags)
|
|
|
+}
|
|
|
+
|
|
|
+### Time-based targets for portal scheduler:
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_quarter_hourly" {
|
|
|
+ target_id = "PortalSchedulerQuarterHourly"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_quarter_hourly_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"quarter-hourly\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_half_hourly" {
|
|
|
+ target_id = "PortalSchedulerHalfHourly"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_half_hourly_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"half-hourly\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_hourly" {
|
|
|
+ target_id = "PortalSchedulerHourly"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_hourly_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"hourly\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_four_hourly" {
|
|
|
+ target_id = "PortalSchedulerFourHourly"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_four_hourly_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"four-hourly\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_daily" {
|
|
|
+ target_id = "PortalSchedulerDaily"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_daily_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"daily\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_weekly" {
|
|
|
+ target_id = "PortalSchedulerWeekly"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_weekly_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"weekly\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_cloudwatch_event_target" "portal_scheduler_cloudwatch_target_monthly" {
|
|
|
+ target_id = "PortalSchedulerMonthly"
|
|
|
+ rule = aws_cloudwatch_event_rule.portal_scheduler_monthly_rule.name
|
|
|
+ input = "{\"frequency_identifier\":\"monthly\"}"
|
|
|
+ arn = aws_lambda_function.portal_scheduler.arn
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+### Invoke permissions for Time-based rules for portal sync:
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_quarter_hourly" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchQuarterHourly"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_quarter_hourly_rule.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_half_hourly" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchHalfHourly"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_half_hourly_rule.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_hourly" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchHourly"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_hourly_rule.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_four_hourly" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchFourHourly"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_four_hourly_rule.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_daily" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchDaily"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_daily_rule.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_weekly" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchWeekly"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_weekly_rule.arn
|
|
|
+}
|
|
|
+
|
|
|
+resource "aws_lambda_permission" "allow_cloudwatch_to_call_portal_scheduler_monthly" {
|
|
|
+ statement_id = "AllowExecutionFromCloudWatchMonthly"
|
|
|
+ action = "lambda:InvokeFunction"
|
|
|
+ function_name = aws_lambda_function.portal_scheduler.function_name
|
|
|
+ principal = "events.amazonaws.com"
|
|
|
+ source_arn = aws_cloudwatch_event_rule.portal_scheduler_monthly_rule.arn
|
|
|
+}
|