Skip to content

Commit 5275096

Browse files
committed
setup events
1 parent 11c76be commit 5275096

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

src/data-archive/main.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ def default(self, o):
3030
TimestampMapper = Dict[str, Callable[[Dict[str, Any]], str]]
3131

3232
ARCHIVE_TIMESTAMP_MAPPER: TimestampMapper = {
33-
"infra-core-api-room-requests-status": lambda x: x["createdAt#status"].split("#")[0]
33+
"infra-core-api-room-requests-status": lambda x: x["createdAt#status"].split("#")[
34+
0
35+
],
36+
"infra-core-api-events": lambda x: x["createdAt"],
37+
"infra-core-api-audit-log": lambda x: datetime.fromtimestamp(x["createdAt"])
38+
.astimezone(timezone.utc)
39+
.isoformat(),
3440
}
3541

3642

@@ -73,14 +79,22 @@ def lambda_handler(event, context):
7379

7480
# 4. Construct the Payload
7581
payload = {
76-
"table": table_name,
77-
"data": deserialized_data,
78-
"timestamp": datetime.now(timezone.utc).isoformat(),
82+
**deserialized_data,
83+
"__infra_archive_table": table_name,
84+
"__infra_archive_timestamp": datetime.now(timezone.utc).strftime(
85+
"%Y-%m-%dT%H:%M:%SZ"
86+
),
7987
}
8088
if table_name in ARCHIVE_TIMESTAMP_MAPPER:
8189
try:
82-
payload["timestamp"] = ARCHIVE_TIMESTAMP_MAPPER[table_name](
83-
deserialized_data
90+
payload["__infra_archive_timestamp"] = (
91+
(
92+
datetime.fromisoformat(
93+
ARCHIVE_TIMESTAMP_MAPPER[table_name](deserialized_data)
94+
)
95+
)
96+
.astimezone(timezone.utc)
97+
.strftime("%Y-%m-%dT%H:%M:%SZ")
8498
)
8599
except Exception as e:
86100
logger.error(

terraform/envs/prod/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ module "alarms" {
6565
resource_prefix = var.ProjectId
6666
main_cloudfront_distribution_id = module.frontend.main_cloudfront_distribution_id
6767
standard_sns_arn = var.GeneralSNSAlertArn
68-
all_lambdas = toset([module.lambdas.core_api_lambda_name, module.lambdas.core_api_slow_lambda_name, module.lambdas.core_sqs_consumer_lambda_name])
69-
performance_noreq_lambdas = toset([module.lambdas.core_api_lambda_name])
68+
all_lambdas = toset([
69+
module.lambdas.core_api_lambda_name,
70+
module.lambdas.core_api_slow_lambda_name,
71+
module.lambdas.core_sqs_consumer_lambda_name
72+
])
73+
performance_noreq_lambdas = toset([module.lambdas.core_api_lambda_name])
7074
}
7175

7276
module "lambdas" {

terraform/envs/qa/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module "ttl_archiver" {
6363
RunEnvironment = "dev"
6464
LogRetentionDays = var.LogRetentionDays
6565
BucketPrefix = local.bucket_prefix
66-
MonitorTables = ["${var.ProjectId}-room-requests", "${var.ProjectId}-room-requests-status"]
66+
MonitorTables = ["${var.ProjectId}-audit-log", "${var.ProjectId}-events", "${var.ProjectId}-room-requests", "${var.ProjectId}-room-requests-status"]
6767
}
6868

6969
resource "aws_cloudfront_key_value_store" "linkry_kv" {

terraform/modules/alarms/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ resource "aws_cloudwatch_metric_alarm" "app_no_requests_alarm" {
6565
resource "aws_cloudwatch_metric_alarm" "app_invocation_error_alarm" {
6666
for_each = var.all_lambdas
6767
alarm_name = "${each.value}-error-invocation"
68-
alarm_description = "${replace(each.value, var.resource_prefix, "")} lambda threw an error, meaning the init of the application itself has encountered an error"
68+
alarm_description = "${replace(each.value, var.resource_prefix, "")} lambda threw a critical error."
6969
namespace = "AWS/Lambda"
7070
metric_name = "Errors"
7171
statistic = "Sum"

terraform/modules/archival/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ resource "aws_kinesis_firehose_delivery_stream" "dynamic_stream" {
197197
type = "MetadataExtraction"
198198
parameters {
199199
parameter_name = "MetadataExtractionQuery"
200-
parameter_value = "{table: .table, year: (.timestamp | strftime(\"%Y\")), month: (.timestamp | strftime(\"%m\")), day: (.timestamp | strftime(\"%d\"))}"
200+
parameter_value = "{table: .__infra_archive_table, year: (.__infra_archive_timestamp | fromdateiso8601 | strftime(\"%Y\")), month: (.__infra_archive_timestamp | fromdateiso8601 | strftime(\"%m\")), day: (.__infra_archive_timestamp | fromdateiso8601 | strftime(\"%d\"))}"
201201
}
202202
parameters {
203203
parameter_name = "JsonParsingEngine"
@@ -283,3 +283,11 @@ resource "aws_lambda_function" "api_lambda" {
283283
}
284284
}
285285
}
286+
287+
output "archival_lambda_name" {
288+
value = local.archive_lambda_name
289+
}
290+
291+
output "firehose_stream_name" {
292+
value = local.firehose_stream_name
293+
}

0 commit comments

Comments
 (0)