From b575efc72308b691994e60fe9a9adc0b7f036afa Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Tue, 3 Mar 2026 16:18:14 +0000 Subject: [PATCH 1/8] CCM-14044 Setting prod defaults --- .../terraform/components/api/README.md | 6 ++- .../components/api/modules_eventpub.tf | 9 ++++- .../terraform/components/api/variables.tf | 24 +++++++++++ .../terraform/modules/eventsub/README.md | 5 +++ ...udwatch_metric_alarm_subscriber_anomaly.tf | 40 +++++++++++++++++++ .../terraform/modules/eventsub/outputs.tf | 9 +++++ .../terraform/modules/eventsub/variables.tf | 33 +++++++++++++++ 7 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf diff --git a/infrastructure/terraform/components/api/README.md b/infrastructure/terraform/components/api/README.md index 4fc886b42..87bed5e63 100644 --- a/infrastructure/terraform/components/api/README.md +++ b/infrastructure/terraform/components/api/README.md @@ -21,8 +21,12 @@ No requirements. | [enable\_api\_data\_trace](#input\_enable\_api\_data\_trace) | Enable API Gateway data trace logging | `bool` | `false` | no | | [enable\_backups](#input\_enable\_backups) | Enable backups | `bool` | `false` | no | | [enable\_event\_cache](#input\_enable\_event\_cache) | Enable caching of events to an S3 bucket | `bool` | `true` | no | +| [enable\_event\_publishing\_anomaly\_detection](#input\_enable\_event\_publishing\_anomaly\_detection) | Enable CloudWatch anomaly detection alarm for SNS message publishing. Detects abnormal drops or spikes in event publishing volume. | `bool` | `true` | no | | [enable\_sns\_delivery\_logging](#input\_enable\_sns\_delivery\_logging) | Enable SNS Delivery Failure Notifications | `bool` | `true` | no | | [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes | +| [event\_publishing\_anomaly\_band\_width](#input\_event\_publishing\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `5` | no | +| [event\_publishing\_anomaly\_evaluation\_periods](#input\_event\_publishing\_anomaly\_evaluation\_periods) | Number of evaluation periods for the publishing anomaly alarm. Each period is defined by event\_publishing\_anomaly\_period. | `number` | `3` | no | +| [event\_publishing\_anomaly\_period](#input\_event\_publishing\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no | | [eventpub\_control\_plane\_bus\_arn](#input\_eventpub\_control\_plane\_bus\_arn) | ARN of the EventBridge control plane bus for eventpub | `string` | `""` | no | | [eventpub\_data\_plane\_bus\_arn](#input\_eventpub\_data\_plane\_bus\_arn) | ARN of the EventBridge data plane bus for eventpub | `string` | `""` | no | | [force\_destroy](#input\_force\_destroy) | Flag to force deletion of S3 buckets | `bool` | `false` | no | @@ -52,7 +56,7 @@ No requirements. | [ddb\_alarms\_mi](#module\_ddb\_alarms\_mi) | ../../modules/alarms-ddb | n/a | | [ddb\_alarms\_suppliers](#module\_ddb\_alarms\_suppliers) | ../../modules/alarms-ddb | n/a | | [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a | -| [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.31/terraform-eventpub.zip | n/a | +| [eventpub](#module\_eventpub) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/terraform/modules/eventpub | 3.0.4 | | [eventsub](#module\_eventsub) | ../../modules/eventsub | n/a | | [get\_letter](#module\_get\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | diff --git a/infrastructure/terraform/components/api/modules_eventpub.tf b/infrastructure/terraform/components/api/modules_eventpub.tf index 83547ea62..d8c54783e 100644 --- a/infrastructure/terraform/components/api/modules_eventpub.tf +++ b/infrastructure/terraform/components/api/modules_eventpub.tf @@ -1,5 +1,5 @@ module "eventpub" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.31/terraform-eventpub.zip" + source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/terraform/modules/eventpub?ref=3.0.4" name = "eventpub" @@ -31,7 +31,14 @@ module "eventpub" { additional_policies_for_event_cache_bucket = [ data.aws_iam_policy_document.eventcache[0].json ] + + # CloudWatch Anomaly Detection for publishing + enable_event_publishing_anomaly_detection = var.enable_event_publishing_anomaly_detection + event_publishing_anomaly_band_width = var.event_publishing_anomaly_band_width + event_publishing_anomaly_evaluation_periods = var.event_publishing_anomaly_evaluation_periods + event_publishing_anomaly_period = var.event_publishing_anomaly_period } + data "aws_iam_policy_document" "eventcache" { count = local.event_cache_bucket_name != null ? 1 : 0 statement { diff --git a/infrastructure/terraform/components/api/variables.tf b/infrastructure/terraform/components/api/variables.tf index 4559f30b9..71ca299f0 100644 --- a/infrastructure/terraform/components/api/variables.tf +++ b/infrastructure/terraform/components/api/variables.tf @@ -199,3 +199,27 @@ variable "enable_alarms" { description = "Enable CloudWatch alarms for this deployed environment" default = true } + +variable "enable_event_publishing_anomaly_detection" { + type = bool + description = "Enable CloudWatch anomaly detection alarm for SNS message publishing. Detects abnormal drops or spikes in event publishing volume." + default = true +} + +variable "event_publishing_anomaly_evaluation_periods" { + type = number + description = "Number of evaluation periods for the publishing anomaly alarm. Each period is defined by event_publishing_anomaly_period." + default = 3 +} + +variable "event_publishing_anomaly_period" { + type = number + description = "The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600." + default = 300 +} + +variable "event_publishing_anomaly_band_width" { + type = number + description = "The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4." + default = 5 +} diff --git a/infrastructure/terraform/modules/eventsub/README.md b/infrastructure/terraform/modules/eventsub/README.md index 9aadbb3f2..3b00812e8 100644 --- a/infrastructure/terraform/modules/eventsub/README.md +++ b/infrastructure/terraform/modules/eventsub/README.md @@ -14,10 +14,14 @@ | [aws\_account\_id](#input\_aws\_account\_id) | The AWS Account ID (numeric) | `string` | n/a | yes | | [component](#input\_component) | The name of the terraformscaffold component calling this module | `string` | n/a | yes | | [default\_tags](#input\_default\_tags) | Default tag map for application to all taggable resources in the module | `map(string)` | `{}` | no | +| [enable\_event\_anomaly\_detection](#input\_enable\_event\_anomaly\_detection) | Enable CloudWatch anomaly detection alarm for SNS topic message publishing | `bool` | `true` | no | | [enable\_event\_cache](#input\_enable\_event\_cache) | Enable caching of events to an S3 bucket | `bool` | `true` | no | | [enable\_firehose\_raw\_message\_delivery](#input\_enable\_firehose\_raw\_message\_delivery) | Enables raw message delivery on firehose subscription | `bool` | `false` | no | | [enable\_sns\_delivery\_logging](#input\_enable\_sns\_delivery\_logging) | Enable SNS Delivery Failure Notifications | `bool` | `true` | no | | [environment](#input\_environment) | The name of the terraformscaffold environment the module is called for | `string` | n/a | yes | +| [event\_anomaly\_band\_width](#input\_event\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `3` | no | +| [event\_anomaly\_evaluation\_periods](#input\_event\_anomaly\_evaluation\_periods) | Number of evaluation periods for the anomaly alarm. Each period is defined by event\_anomaly\_period. | `number` | `2` | no | +| [event\_anomaly\_period](#input\_event\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no | | [event\_cache\_buffer\_interval](#input\_event\_cache\_buffer\_interval) | The buffer interval for data firehose | `number` | `500` | no | | [event\_cache\_expiry\_days](#input\_event\_cache\_expiry\_days) | s3 archiving expiry in days | `number` | `30` | no | | [force\_destroy](#input\_force\_destroy) | When enabled will force destroy event-cache S3 bucket | `bool` | `false` | no | @@ -42,6 +46,7 @@ |------|-------------| | [s3\_bucket\_event\_cache](#output\_s3\_bucket\_event\_cache) | S3 Bucket ARN and Name for event cache | | [sns\_topic](#output\_sns\_topic) | SNS Topic ARN and Name | +| [subscriber\_anomaly\_alarm](#output\_subscriber\_anomaly\_alarm) | Subscriber anomaly detection alarm details | diff --git a/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf b/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf new file mode 100644 index 000000000..cf93c98b4 --- /dev/null +++ b/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf @@ -0,0 +1,40 @@ +resource "aws_cloudwatch_metric_alarm" "subscriber_anomaly" { + count = var.enable_event_anomaly_detection ? 1 : 0 + + alarm_name = "${local.csi}-subscriber-anomaly" + alarm_description = "ANOMALY: Detects anomalous patterns in messages published to the SNS fanout topic" + comparison_operator = "LessThanLowerOrGreaterThanUpperThreshold" + evaluation_periods = var.event_anomaly_evaluation_periods + threshold_metric_id = "ad1" + treat_missing_data = "notBreaching" + + metric_query { + id = "m1" + return_data = true + + metric { + metric_name = "NumberOfMessagesPublished" + namespace = "AWS/SNS" + period = var.event_anomaly_period + stat = "Sum" + + dimensions = { + TopicName = aws_sns_topic.main.name + } + } + } + + metric_query { + id = "ad1" + expression = "ANOMALY_DETECTION_BAND(m1, ${var.event_anomaly_band_width})" + label = "NumberOfMessagesPublished (expected)" + return_data = true + } + + tags = merge( + var.default_tags, + { + Name = "${local.csi}-subscriber-anomaly" + } + ) +} diff --git a/infrastructure/terraform/modules/eventsub/outputs.tf b/infrastructure/terraform/modules/eventsub/outputs.tf index e2ff3b38e..dac709421 100644 --- a/infrastructure/terraform/modules/eventsub/outputs.tf +++ b/infrastructure/terraform/modules/eventsub/outputs.tf @@ -13,3 +13,12 @@ output "s3_bucket_event_cache" { bucket = module.s3bucket_event_cache[0].bucket } : {} } + +# CloudWatch Anomaly Detection Alarm +output "subscriber_anomaly_alarm" { + description = "Subscriber anomaly detection alarm details" + value = var.enable_event_anomaly_detection ? { + arn = aws_cloudwatch_metric_alarm.subscriber_anomaly[0].arn + name = aws_cloudwatch_metric_alarm.subscriber_anomaly[0].alarm_name + } : null +} diff --git a/infrastructure/terraform/modules/eventsub/variables.tf b/infrastructure/terraform/modules/eventsub/variables.tf index f808bcb4a..c1a725a55 100644 --- a/infrastructure/terraform/modules/eventsub/variables.tf +++ b/infrastructure/terraform/modules/eventsub/variables.tf @@ -79,6 +79,39 @@ variable "sns_success_logging_sample_percent" { default = 0 } +## +# CloudWatch Anomaly Detection Variables +## + +variable "enable_event_anomaly_detection" { + type = bool + description = "Enable CloudWatch anomaly detection alarm for SNS topic message publishing" + default = true +} + +variable "event_anomaly_evaluation_periods" { + type = number + description = "Number of evaluation periods for the anomaly alarm. Each period is defined by event_anomaly_period." + default = 2 +} + +variable "event_anomaly_period" { + type = number + description = "The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600." + default = 300 +} + +variable "event_anomaly_band_width" { + type = number + description = "The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4." + default = 3 + + validation { + condition = var.event_anomaly_band_width >= 2 && var.event_anomaly_band_width <= 10 + error_message = "Band width must be between 2 and 10" + } +} + variable "log_level" { type = string description = "The log level to be used in lambda functions within the component. Any log with a lower severity than the configured value will not be logged: https://docs.python.org/3/library/logging.html#levels" From d9ff0a9d486981781362af3a1ec7759745d61482 Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 11:30:00 +0000 Subject: [PATCH 2/8] CCM-14044 Setting prod defaults --- infrastructure/terraform/components/api/modules_eventpub.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infrastructure/terraform/components/api/modules_eventpub.tf b/infrastructure/terraform/components/api/modules_eventpub.tf index d8c54783e..cb46e3ab3 100644 --- a/infrastructure/terraform/components/api/modules_eventpub.tf +++ b/infrastructure/terraform/components/api/modules_eventpub.tf @@ -21,12 +21,12 @@ module "eventpub" { event_cache_buffer_interval = 500 enable_sns_delivery_logging = var.enable_sns_delivery_logging sns_success_logging_sample_percent = var.sns_success_logging_sample_percent + access_logging_bucket = local.acct.s3_buckets["access_logs"]["id"] event_cache_expiry_days = 30 enable_event_cache = var.enable_event_cache - - data_plane_bus_arn = var.eventpub_data_plane_bus_arn - control_plane_bus_arn = var.eventpub_control_plane_bus_arn + data_plane_bus_arn = var.eventpub_data_plane_bus_arn + control_plane_bus_arn = var.eventpub_control_plane_bus_arn additional_policies_for_event_cache_bucket = [ data.aws_iam_policy_document.eventcache[0].json From 281824f63f3c3bc550526dd81edc638b6e54b982 Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 11:40:36 +0000 Subject: [PATCH 3/8] CCM-14044 Fixing mod source --- infrastructure/terraform/components/api/README.md | 2 +- infrastructure/terraform/components/api/modules_eventpub.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/terraform/components/api/README.md b/infrastructure/terraform/components/api/README.md index 87bed5e63..914ac5ef7 100644 --- a/infrastructure/terraform/components/api/README.md +++ b/infrastructure/terraform/components/api/README.md @@ -56,7 +56,7 @@ No requirements. | [ddb\_alarms\_mi](#module\_ddb\_alarms\_mi) | ../../modules/alarms-ddb | n/a | | [ddb\_alarms\_suppliers](#module\_ddb\_alarms\_suppliers) | ../../modules/alarms-ddb | n/a | | [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a | -| [eventpub](#module\_eventpub) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/terraform/modules/eventpub | 3.0.4 | +| [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-eventpub.zip | n/a | | [eventsub](#module\_eventsub) | ../../modules/eventsub | n/a | | [get\_letter](#module\_get\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | diff --git a/infrastructure/terraform/components/api/modules_eventpub.tf b/infrastructure/terraform/components/api/modules_eventpub.tf index cb46e3ab3..dd6bb6918 100644 --- a/infrastructure/terraform/components/api/modules_eventpub.tf +++ b/infrastructure/terraform/components/api/modules_eventpub.tf @@ -1,5 +1,5 @@ module "eventpub" { - source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/terraform/modules/eventpub?ref=3.0.4" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-eventpub.zip" name = "eventpub" From 1c64bb88268b82bfe5f82698fbc48d361b883203 Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 20:14:00 +0000 Subject: [PATCH 4/8] CCM-14044 Fixing Var Names --- infrastructure/terraform/components/api/README.md | 10 +++++----- .../terraform/components/api/modules_eventpub.tf | 11 +++++------ infrastructure/terraform/components/api/variables.tf | 12 ++++++------ scripts/config/pre-commit.yaml | 3 +-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/infrastructure/terraform/components/api/README.md b/infrastructure/terraform/components/api/README.md index 914ac5ef7..a1bd85280 100644 --- a/infrastructure/terraform/components/api/README.md +++ b/infrastructure/terraform/components/api/README.md @@ -20,13 +20,13 @@ No requirements. | [enable\_alarms](#input\_enable\_alarms) | Enable CloudWatch alarms for this deployed environment | `bool` | `true` | no | | [enable\_api\_data\_trace](#input\_enable\_api\_data\_trace) | Enable API Gateway data trace logging | `bool` | `false` | no | | [enable\_backups](#input\_enable\_backups) | Enable backups | `bool` | `false` | no | +| [enable\_event\_anomaly\_detection](#input\_enable\_event\_anomaly\_detection) | Enable CloudWatch anomaly detection alarm for SNS message Detects abnormal drops or spikes in event publishing volume. | `bool` | `true` | no | | [enable\_event\_cache](#input\_enable\_event\_cache) | Enable caching of events to an S3 bucket | `bool` | `true` | no | -| [enable\_event\_publishing\_anomaly\_detection](#input\_enable\_event\_publishing\_anomaly\_detection) | Enable CloudWatch anomaly detection alarm for SNS message publishing. Detects abnormal drops or spikes in event publishing volume. | `bool` | `true` | no | | [enable\_sns\_delivery\_logging](#input\_enable\_sns\_delivery\_logging) | Enable SNS Delivery Failure Notifications | `bool` | `true` | no | | [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes | -| [event\_publishing\_anomaly\_band\_width](#input\_event\_publishing\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `5` | no | -| [event\_publishing\_anomaly\_evaluation\_periods](#input\_event\_publishing\_anomaly\_evaluation\_periods) | Number of evaluation periods for the publishing anomaly alarm. Each period is defined by event\_publishing\_anomaly\_period. | `number` | `3` | no | -| [event\_publishing\_anomaly\_period](#input\_event\_publishing\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no | +| [event\_anomaly\_band\_width](#input\_event\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `5` | no | +| [event\_anomaly\_evaluation\_periods](#input\_event\_anomaly\_evaluation\_periods) | Number of evaluation periods for the anomaly alarm. Each period is defined by event\_anomaly\_period. | `number` | `3` | no | +| [event\_anomaly\_period](#input\_event\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no | | [eventpub\_control\_plane\_bus\_arn](#input\_eventpub\_control\_plane\_bus\_arn) | ARN of the EventBridge control plane bus for eventpub | `string` | `""` | no | | [eventpub\_data\_plane\_bus\_arn](#input\_eventpub\_data\_plane\_bus\_arn) | ARN of the EventBridge data plane bus for eventpub | `string` | `""` | no | | [force\_destroy](#input\_force\_destroy) | Flag to force deletion of S3 buckets | `bool` | `false` | no | @@ -56,7 +56,7 @@ No requirements. | [ddb\_alarms\_mi](#module\_ddb\_alarms\_mi) | ../../modules/alarms-ddb | n/a | | [ddb\_alarms\_suppliers](#module\_ddb\_alarms\_suppliers) | ../../modules/alarms-ddb | n/a | | [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a | -| [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-eventpub.zip | n/a | +| [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-eventpub.zip | n/a | | [eventsub](#module\_eventsub) | ../../modules/eventsub | n/a | | [get\_letter](#module\_get\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | diff --git a/infrastructure/terraform/components/api/modules_eventpub.tf b/infrastructure/terraform/components/api/modules_eventpub.tf index dd6bb6918..f202cbfdd 100644 --- a/infrastructure/terraform/components/api/modules_eventpub.tf +++ b/infrastructure/terraform/components/api/modules_eventpub.tf @@ -1,5 +1,5 @@ module "eventpub" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-eventpub.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-eventpub.zip" name = "eventpub" @@ -32,11 +32,10 @@ module "eventpub" { data.aws_iam_policy_document.eventcache[0].json ] - # CloudWatch Anomaly Detection for publishing - enable_event_publishing_anomaly_detection = var.enable_event_publishing_anomaly_detection - event_publishing_anomaly_band_width = var.event_publishing_anomaly_band_width - event_publishing_anomaly_evaluation_periods = var.event_publishing_anomaly_evaluation_periods - event_publishing_anomaly_period = var.event_publishing_anomaly_period + enable_event_anomaly_detection = var.enable_event_anomaly_detection + event_anomaly_band_width = var.event_anomaly_band_width + event_anomaly_evaluation_periods = var.event_anomaly_evaluation_periods + event_anomaly_period = var.event_anomaly_period } data "aws_iam_policy_document" "eventcache" { diff --git a/infrastructure/terraform/components/api/variables.tf b/infrastructure/terraform/components/api/variables.tf index 71ca299f0..99650f559 100644 --- a/infrastructure/terraform/components/api/variables.tf +++ b/infrastructure/terraform/components/api/variables.tf @@ -200,25 +200,25 @@ variable "enable_alarms" { default = true } -variable "enable_event_publishing_anomaly_detection" { +variable "enable_event_anomaly_detection" { type = bool - description = "Enable CloudWatch anomaly detection alarm for SNS message publishing. Detects abnormal drops or spikes in event publishing volume." + description = "Enable CloudWatch anomaly detection alarm for SNS message Detects abnormal drops or spikes in event publishing volume." default = true } -variable "event_publishing_anomaly_evaluation_periods" { +variable "event_anomaly_evaluation_periods" { type = number - description = "Number of evaluation periods for the publishing anomaly alarm. Each period is defined by event_publishing_anomaly_period." + description = "Number of evaluation periods for the anomaly alarm. Each period is defined by event_anomaly_period." default = 3 } -variable "event_publishing_anomaly_period" { +variable "event_anomaly_period" { type = number description = "The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600." default = 300 } -variable "event_publishing_anomaly_band_width" { +variable "event_anomaly_band_width" { type = number description = "The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4." default = 5 diff --git a/scripts/config/pre-commit.yaml b/scripts/config/pre-commit.yaml index 85bce3090..c217b3366 100644 --- a/scripts/config/pre-commit.yaml +++ b/scripts/config/pre-commit.yaml @@ -23,10 +23,9 @@ repos: sdk/.* | someotherdir/.* | src/server/host/Properties/launchSettings.json | + tests/contracts/provider/tsconfig.json | internal/events/.*/.*\.schema\.json )$ - - # - id: ... - repo: local hooks: - id: sort-dictionary From 9a4f5db3af21985da6e23846467d778460b82ce2 Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 20:30:49 +0000 Subject: [PATCH 5/8] CCM-14044 Fixing mod source --- infrastructure/terraform/components/api/README.md | 2 +- infrastructure/terraform/components/api/variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/terraform/components/api/README.md b/infrastructure/terraform/components/api/README.md index a1bd85280..79d6fd1f5 100644 --- a/infrastructure/terraform/components/api/README.md +++ b/infrastructure/terraform/components/api/README.md @@ -24,7 +24,7 @@ No requirements. | [enable\_event\_cache](#input\_enable\_event\_cache) | Enable caching of events to an S3 bucket | `bool` | `true` | no | | [enable\_sns\_delivery\_logging](#input\_enable\_sns\_delivery\_logging) | Enable SNS Delivery Failure Notifications | `bool` | `true` | no | | [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes | -| [event\_anomaly\_band\_width](#input\_event\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `5` | no | +| [event\_anomaly\_band\_width](#input\_event\_anomaly\_band\_width) | The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4. | `number` | `4` | no | | [event\_anomaly\_evaluation\_periods](#input\_event\_anomaly\_evaluation\_periods) | Number of evaluation periods for the anomaly alarm. Each period is defined by event\_anomaly\_period. | `number` | `3` | no | | [event\_anomaly\_period](#input\_event\_anomaly\_period) | The period in seconds over which the specified statistic is applied for anomaly detection. Minimum 300 seconds (5 minutes). Recommended: 300-600. | `number` | `300` | no | | [eventpub\_control\_plane\_bus\_arn](#input\_eventpub\_control\_plane\_bus\_arn) | ARN of the EventBridge control plane bus for eventpub | `string` | `""` | no | diff --git a/infrastructure/terraform/components/api/variables.tf b/infrastructure/terraform/components/api/variables.tf index 99650f559..97169278e 100644 --- a/infrastructure/terraform/components/api/variables.tf +++ b/infrastructure/terraform/components/api/variables.tf @@ -221,5 +221,5 @@ variable "event_anomaly_period" { variable "event_anomaly_band_width" { type = number description = "The width of the anomaly detection band. Higher values (e.g. 4-6) reduce sensitivity and noise, lower values (e.g. 2-3) increase sensitivity. Recommended: 2-4." - default = 5 + default = 4 } From 40c7e46706ce412c0939e26979611a470e82f3be Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 20:35:35 +0000 Subject: [PATCH 6/8] CCM-14044 Fixing mod source --- .../eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf b/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf index cf93c98b4..012969b38 100644 --- a/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf +++ b/infrastructure/terraform/modules/eventsub/cloudwatch_metric_alarm_subscriber_anomaly.tf @@ -13,7 +13,7 @@ resource "aws_cloudwatch_metric_alarm" "subscriber_anomaly" { return_data = true metric { - metric_name = "NumberOfMessagesPublished" + metric_name = "NumberOfNotificationsDelivered" namespace = "AWS/SNS" period = var.event_anomaly_period stat = "Sum" @@ -27,7 +27,7 @@ resource "aws_cloudwatch_metric_alarm" "subscriber_anomaly" { metric_query { id = "ad1" expression = "ANOMALY_DETECTION_BAND(m1, ${var.event_anomaly_band_width})" - label = "NumberOfMessagesPublished (expected)" + label = "NumberOfNotificationsDelivered (expected)" return_data = true } From 7125454481142a180ab66f111f269e98d041a77c Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 20:40:00 +0000 Subject: [PATCH 7/8] CCM-14044 Unused output --- infrastructure/terraform/modules/eventsub/README.md | 1 - infrastructure/terraform/modules/eventsub/outputs.tf | 9 --------- 2 files changed, 10 deletions(-) diff --git a/infrastructure/terraform/modules/eventsub/README.md b/infrastructure/terraform/modules/eventsub/README.md index 3b00812e8..74fb62443 100644 --- a/infrastructure/terraform/modules/eventsub/README.md +++ b/infrastructure/terraform/modules/eventsub/README.md @@ -46,7 +46,6 @@ |------|-------------| | [s3\_bucket\_event\_cache](#output\_s3\_bucket\_event\_cache) | S3 Bucket ARN and Name for event cache | | [sns\_topic](#output\_sns\_topic) | SNS Topic ARN and Name | -| [subscriber\_anomaly\_alarm](#output\_subscriber\_anomaly\_alarm) | Subscriber anomaly detection alarm details | diff --git a/infrastructure/terraform/modules/eventsub/outputs.tf b/infrastructure/terraform/modules/eventsub/outputs.tf index dac709421..e2ff3b38e 100644 --- a/infrastructure/terraform/modules/eventsub/outputs.tf +++ b/infrastructure/terraform/modules/eventsub/outputs.tf @@ -13,12 +13,3 @@ output "s3_bucket_event_cache" { bucket = module.s3bucket_event_cache[0].bucket } : {} } - -# CloudWatch Anomaly Detection Alarm -output "subscriber_anomaly_alarm" { - description = "Subscriber anomaly detection alarm details" - value = var.enable_event_anomaly_detection ? { - arn = aws_cloudwatch_metric_alarm.subscriber_anomaly[0].arn - name = aws_cloudwatch_metric_alarm.subscriber_anomaly[0].alarm_name - } : null -} From 72226027c2e46fa8ecf5fc93b58ec3cf12beb691 Mon Sep 17 00:00:00 2001 From: aidenvaines-cgi Date: Wed, 4 Mar 2026 21:06:45 +0000 Subject: [PATCH 8/8] CCM-14044 Fixing mod refs --- infrastructure/terraform/components/api/README.md | 10 +++++----- .../components/api/module_domain_truststore.tf | 2 +- .../terraform/components/api/module_sqs_amendments.tf | 2 +- .../components/api/module_sqs_letter_status_updates.tf | 2 +- .../components/api/module_sqs_letter_updates.tf | 2 +- .../components/api/module_sqs_supplier_allocator.tf | 2 +- .../terraform/components/api/modules_eventpub.tf | 2 -- infrastructure/terraform/modules/eventsub/README.md | 2 +- .../modules/eventsub/module_s3bucket_event_cache.tf | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/infrastructure/terraform/components/api/README.md b/infrastructure/terraform/components/api/README.md index fc67e4f06..f1f278c5e 100644 --- a/infrastructure/terraform/components/api/README.md +++ b/infrastructure/terraform/components/api/README.md @@ -49,13 +49,13 @@ No requirements. | Name | Source | Version | |------|--------|---------| | [amendment\_event\_transformer](#module\_amendment\_event\_transformer) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | -| [amendments\_queue](#module\_amendments\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a | +| [amendments\_queue](#module\_amendments\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a | | [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [ddb\_alarms\_letter\_queue](#module\_ddb\_alarms\_letter\_queue) | ../../modules/alarms-ddb | n/a | | [ddb\_alarms\_letters](#module\_ddb\_alarms\_letters) | ../../modules/alarms-ddb | n/a | | [ddb\_alarms\_mi](#module\_ddb\_alarms\_mi) | ../../modules/alarms-ddb | n/a | | [ddb\_alarms\_suppliers](#module\_ddb\_alarms\_suppliers) | ../../modules/alarms-ddb | n/a | -| [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a | +| [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-s3bucket.zip | n/a | | [eventpub](#module\_eventpub) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-eventpub.zip | n/a | | [eventsub](#module\_eventsub) | ../../modules/eventsub | n/a | | [get\_letter](#module\_get\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | @@ -64,7 +64,7 @@ No requirements. | [get\_status](#module\_get\_status) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [kms](#module\_kms) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-kms.zip | n/a | | [lambda\_alarms](#module\_lambda\_alarms) | ../../modules/alarms-lambda | n/a | -| [letter\_status\_updates\_queue](#module\_letter\_status\_updates\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a | +| [letter\_status\_updates\_queue](#module\_letter\_status\_updates\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a | | [letter\_updates\_transformer](#module\_letter\_updates\_transformer) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [mi\_updates\_transformer](#module\_mi\_updates\_transformer) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-lambda.zip | n/a | | [patch\_letter](#module\_patch\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | @@ -72,8 +72,8 @@ No requirements. | [post\_mi](#module\_post\_mi) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [s3bucket\_test\_letters](#module\_s3bucket\_test\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-s3bucket.zip | n/a | | [sqs\_alarms](#module\_sqs\_alarms) | ../../modules/alarms-sqs | n/a | -| [sqs\_letter\_updates](#module\_sqs\_letter\_updates) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-sqs.zip | n/a | -| [sqs\_supplier\_allocator](#module\_sqs\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-sqs.zip | n/a | +| [sqs\_letter\_updates](#module\_sqs\_letter\_updates) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a | +| [sqs\_supplier\_allocator](#module\_sqs\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a | | [supplier\_allocator](#module\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | | [supplier\_ssl](#module\_supplier\_ssl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-ssl.zip | n/a | | [update\_letter\_queue](#module\_update\_letter\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a | diff --git a/infrastructure/terraform/components/api/module_domain_truststore.tf b/infrastructure/terraform/components/api/module_domain_truststore.tf index 77a927101..a0f479cf4 100644 --- a/infrastructure/terraform/components/api/module_domain_truststore.tf +++ b/infrastructure/terraform/components/api/module_domain_truststore.tf @@ -1,5 +1,5 @@ module "domain_truststore" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-s3bucket.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-s3bucket.zip" name = "truststore" aws_account_id = var.aws_account_id diff --git a/infrastructure/terraform/components/api/module_sqs_amendments.tf b/infrastructure/terraform/components/api/module_sqs_amendments.tf index f5d733c61..8fca10e9d 100644 --- a/infrastructure/terraform/components/api/module_sqs_amendments.tf +++ b/infrastructure/terraform/components/api/module_sqs_amendments.tf @@ -1,6 +1,6 @@ # Queue to transport letter status amendment messages module "amendments_queue" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-sqs.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip" name = "amendments_queue" diff --git a/infrastructure/terraform/components/api/module_sqs_letter_status_updates.tf b/infrastructure/terraform/components/api/module_sqs_letter_status_updates.tf index 2ce3afe55..db7d27a85 100644 --- a/infrastructure/terraform/components/api/module_sqs_letter_status_updates.tf +++ b/infrastructure/terraform/components/api/module_sqs_letter_status_updates.tf @@ -1,7 +1,7 @@ # Queue to transport update letter status messages. Now replaced by module.amendments_queue. # This queue will not be removed just yet, to allow it to be drained following the release in which module.amendments_queue replaces it. module "letter_status_updates_queue" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-sqs.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip" name = "letter_status_updates_queue" diff --git a/infrastructure/terraform/components/api/module_sqs_letter_updates.tf b/infrastructure/terraform/components/api/module_sqs_letter_updates.tf index 1355e08bc..1e886d61e 100644 --- a/infrastructure/terraform/components/api/module_sqs_letter_updates.tf +++ b/infrastructure/terraform/components/api/module_sqs_letter_updates.tf @@ -1,5 +1,5 @@ module "sqs_letter_updates" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-sqs.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip" aws_account_id = var.aws_account_id component = var.component diff --git a/infrastructure/terraform/components/api/module_sqs_supplier_allocator.tf b/infrastructure/terraform/components/api/module_sqs_supplier_allocator.tf index 7ee7d45f0..565038d7b 100644 --- a/infrastructure/terraform/components/api/module_sqs_supplier_allocator.tf +++ b/infrastructure/terraform/components/api/module_sqs_supplier_allocator.tf @@ -1,5 +1,5 @@ module "sqs_supplier_allocator" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.5/terraform-sqs.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip" aws_account_id = var.aws_account_id component = var.component diff --git a/infrastructure/terraform/components/api/modules_eventpub.tf b/infrastructure/terraform/components/api/modules_eventpub.tf index 5ae7eab9b..f202cbfdd 100644 --- a/infrastructure/terraform/components/api/modules_eventpub.tf +++ b/infrastructure/terraform/components/api/modules_eventpub.tf @@ -28,8 +28,6 @@ module "eventpub" { data_plane_bus_arn = var.eventpub_data_plane_bus_arn control_plane_bus_arn = var.eventpub_control_plane_bus_arn - access_logging_bucket = local.acct.s3_buckets["access_logs"]["id"] - additional_policies_for_event_cache_bucket = [ data.aws_iam_policy_document.eventcache[0].json ] diff --git a/infrastructure/terraform/modules/eventsub/README.md b/infrastructure/terraform/modules/eventsub/README.md index 718718374..4ddc516e1 100644 --- a/infrastructure/terraform/modules/eventsub/README.md +++ b/infrastructure/terraform/modules/eventsub/README.md @@ -40,7 +40,7 @@ | Name | Source | Version | |------|--------|---------| -| [s3bucket\_event\_cache](#module\_s3bucket\_event\_cache) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-s3bucket.zip | n/a | +| [s3bucket\_event\_cache](#module\_s3bucket\_event\_cache) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-s3bucket.zip | n/a | ## Outputs | Name | Description | diff --git a/infrastructure/terraform/modules/eventsub/module_s3bucket_event_cache.tf b/infrastructure/terraform/modules/eventsub/module_s3bucket_event_cache.tf index 9e610641f..10ba75639 100644 --- a/infrastructure/terraform/modules/eventsub/module_s3bucket_event_cache.tf +++ b/infrastructure/terraform/modules/eventsub/module_s3bucket_event_cache.tf @@ -1,5 +1,5 @@ module "s3bucket_event_cache" { - source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.4/terraform-s3bucket.zip" + source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-s3bucket.zip" count = var.enable_event_cache ? 1 : 0