Skip to content

Commit 2772179

Browse files
[PRMP-1420] Re-enable DataCollection/StatisticalReport lambdas (#231)
1 parent d3ff5bf commit 2772179

3 files changed

Lines changed: 70 additions & 8 deletions

File tree

infrastructure/lambda-data-collection.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ module "data-collection-alarm-topic" {
4141
}
4242

4343
module "data-collection-lambda" {
44-
source = "./modules/lambda"
45-
name = "DataCollectionLambda"
46-
handler = "handlers.data_collection_handler.lambda_handler"
47-
lambda_timeout = 900
44+
source = "./modules/lambda"
45+
name = "DataCollectionLambda"
46+
handler = "handlers.data_collection_handler.lambda_handler"
47+
lambda_timeout = 900
48+
lambda_ephemeral_storage = local.is_production ? 10240 : 1769
49+
memory_size = local.is_production ? 10240 : 1769
4850
iam_role_policy_documents = [
4951
module.ndr-app-config.app_config_policy,
5052
module.statistics_dynamodb_table.dynamodb_read_policy_document,

infrastructure/lambda-statistical-report.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ module "statistical-report-alarm-topic" {
4141
}
4242

4343
module "statistical-report-lambda" {
44-
source = "./modules/lambda"
45-
name = "StatisticalReportLambda"
46-
handler = "handlers.statistical_report_handler.lambda_handler"
47-
lambda_timeout = 900
44+
source = "./modules/lambda"
45+
name = "StatisticalReportLambda"
46+
handler = "handlers.statistical_report_handler.lambda_handler"
47+
lambda_timeout = 900
48+
lambda_ephemeral_storage = local.is_production ? 10240 : 1769
49+
memory_size = local.is_production ? 10240 : 1769
4850
iam_role_policy_documents = [
4951
module.ndr-app-config.app_config_policy,
5052
module.statistics_dynamodb_table.dynamodb_read_policy_document,

infrastructure/schedules.tf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,64 @@ resource "aws_lambda_permission" "bulk_upload_report_schedule_permission" {
5757
]
5858
}
5959

60+
resource "aws_cloudwatch_event_rule" "data_collection_schedule" {
61+
name = "${terraform.workspace}_data_collection_schedule"
62+
description = "Schedule for Data Collection Lambda"
63+
schedule_expression = "cron(0 20 ? * SAT *)"
64+
}
65+
66+
resource "aws_cloudwatch_event_target" "data_collection_schedule_event" {
67+
rule = aws_cloudwatch_event_rule.data_collection_schedule.name
68+
target_id = "data_collection_schedule"
69+
70+
arn = module.data-collection-lambda.lambda_arn
71+
depends_on = [
72+
module.data-collection-lambda,
73+
aws_cloudwatch_event_rule.data_collection_schedule
74+
]
75+
}
76+
77+
resource "aws_lambda_permission" "data_collection_schedule_permission" {
78+
statement_id = "AllowExecutionFromCloudWatch"
79+
action = "lambda:InvokeFunction"
80+
function_name = module.data-collection-lambda.function_name
81+
principal = "events.amazonaws.com"
82+
source_arn = aws_cloudwatch_event_rule.data_collection_schedule.arn
83+
depends_on = [
84+
module.data-collection-lambda,
85+
aws_cloudwatch_event_rule.data_collection_schedule
86+
]
87+
}
88+
89+
resource "aws_cloudwatch_event_rule" "statistical_report_schedule" {
90+
name = "${terraform.workspace}_statistical_report_schedule"
91+
description = "Schedule for Statistical Report Lambda"
92+
schedule_expression = "cron(0 8 ? * MON *)"
93+
}
94+
95+
resource "aws_cloudwatch_event_target" "statistical_report_schedule_event" {
96+
rule = aws_cloudwatch_event_rule.statistical_report_schedule.name
97+
target_id = "statistical_report_schedule"
98+
99+
arn = module.statistical-report-lambda.lambda_arn
100+
depends_on = [
101+
module.statistical-report-lambda,
102+
aws_cloudwatch_event_rule.statistical_report_schedule
103+
]
104+
}
105+
106+
resource "aws_lambda_permission" "statistical_report_schedule_permission" {
107+
statement_id = "AllowExecutionFromCloudWatch"
108+
action = "lambda:InvokeFunction"
109+
function_name = module.statistical-report-lambda.function_name
110+
principal = "events.amazonaws.com"
111+
source_arn = aws_cloudwatch_event_rule.statistical_report_schedule.arn
112+
depends_on = [
113+
module.statistical-report-lambda,
114+
aws_cloudwatch_event_rule.statistical_report_schedule
115+
]
116+
}
117+
60118
resource "aws_scheduler_schedule" "ods_weekly_update_ecs" {
61119
count = local.is_sandbox ? 0 : 1
62120
name_prefix = "${terraform.workspace}_ods_weekly_update_ecs"

0 commit comments

Comments
 (0)