Skip to content

Commit 8f8fc87

Browse files
committed
terraform and code changes on mns_publish
1 parent 0657096 commit 8f8fc87

8 files changed

Lines changed: 46 additions & 42 deletions

File tree

infrastructure/instance/mns_publisher.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module "mns_publisher" {
77
enable_lambda_alarm = var.error_alarm_notifications_enabled # consider just INT and PROD
88
immunisation_account_id = var.immunisation_account_id
99
is_temp = local.is_temp
10+
enable_mns_test_queue = var.mns_environment == "dev"
1011
resource_scope = local.resource_scope
1112
imms_base_path = strcontains(var.sub_environment, "pr-") ? "immunisation-fhir-api/FHIR/R4-${var.sub_environment}" : "immunisation-fhir-api/FHIR/R4"
1213
lambda_kms_encryption_key_arn = data.aws_kms_key.existing_lambda_encryption_key.arn

infrastructure/instance/modules/mns_publisher/mns_publisher_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ resource "aws_lambda_function" "mns_publisher_lambda" {
192192
environment {
193193
variables = {
194194
SPLUNK_FIREHOSE_NAME = var.splunk_firehose_stream_name
195-
MNS_TEST_QUEUE_URL = aws_sqs_queue.mns_test_notification[0].url
195+
MNS_TEST_QUEUE_URL = var.enable_mns_test_queue ? aws_sqs_queue.mns_test_notification[0].url : ""
196196
IMMUNIZATION_ENV = var.resource_scope,
197197
IMMUNIZATION_BASE_PATH = var.imms_base_path
198198
PDS_ENV = var.pds_environment

infrastructure/instance/modules/mns_publisher/sqs_test_publish_mns.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_sqs_queue" "mns_test_notification" {
2-
count = var.mns_environment == "dev" ? 1 : 0
2+
count = var.enable_mns_test_queue ? 1 : 0
33
name = "${var.mns_test_notification_name_prefix}-queue"
44
fifo_queue = false
55
message_retention_seconds = 86400
@@ -8,7 +8,7 @@ resource "aws_sqs_queue" "mns_test_notification" {
88

99

1010
data "aws_iam_policy_document" "mns_test_notification_sqs_policy" {
11-
count = var.mns_environment == "dev" ? 1 : 0
11+
count = var.enable_mns_test_queue ? 1 : 0
1212
statement {
1313
sid = "mns-test-notification-allow-lambda-access"
1414
effect = "Allow"
@@ -29,18 +29,17 @@ data "aws_iam_policy_document" "mns_test_notification_sqs_policy" {
2929
}
3030

3131
resource "aws_sqs_queue_policy" "mns_test_notification_sqs" {
32-
count = var.mns_environment == "dev" ? 1 : 0
32+
count = var.enable_mns_test_queue ? 1 : 0
3333
queue_url = aws_sqs_queue.mns_test_notification[0].id
3434
policy = data.aws_iam_policy_document.mns_test_notification_sqs_policy[0].json
3535
}
3636

3737
output "mns_test_queue_url" {
38-
value = var.mns_environment == "dev" ? aws_sqs_queue.mns_test_notification[0].url : null
38+
value = var.enable_mns_test_queue ? aws_sqs_queue.mns_test_notification[0].url : null
3939
description = "URL of the MNS test notifications queue"
4040
}
4141

4242
output "mns_test_queue_arn" {
43-
value = var.mns_environment == "dev" ? aws_sqs_queue.mns_test_notification[0].arn : 0
43+
value = var.enable_mns_test_queue ? aws_sqs_queue.mns_test_notification[0].arn : null
4444
description = "ARN of the MNS test notifications queue"
45-
}
46-
45+
}

infrastructure/instance/modules/mns_publisher/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ variable "secrets_manager_policy_path" {
107107
variable "mns_test_notification_name_prefix" {
108108
type = string
109109
description = "The prefix for the name of resources for testing mns notification"
110+
}
111+
112+
variable "enable_mns_test_queue" {
113+
description = "Enable test SQS queue for MNS notifications (dev only)"
114+
type = bool
115+
default = false
110116
}
Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,5 @@
1-
from typing import TypedDict
2-
31
# Static constants for the MNS notification creation process
42
SPEC_VERSION = "1.0"
53
IMMUNISATION_TYPE = "imms-vaccinations-1"
64

7-
8-
# Fields from the incoming SQS message that forms part of the base schema and filtering attributes for MNS notifications
9-
class FilteringData(TypedDict):
10-
"""MNS notification filtering attributes."""
11-
12-
generalpractitioner: str | None
13-
sourceorganisation: str
14-
sourceapplication: str
15-
subjectage: int
16-
immunisationtype: str
17-
action: str
18-
19-
20-
class MnsNotificationPayload(TypedDict):
21-
"""CloudEvents-compliant MNS notification payload."""
22-
23-
specversion: str
24-
id: str
25-
source: str
26-
type: str
27-
time: str
28-
subject: str
29-
dataref: str
30-
filtering: FilteringData
31-
32-
335
DYNAMO_DB_TYPE_DESCRIPTORS = ("S", "N", "BOOL", "M", "L")

lambdas/mns_publisher/src/create_notification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
from aws_lambda_typing.events.sqs import SQSMessage
88

9+
from common.api_clients.constants import MnsNotificationPayload
910
from common.api_clients.get_pds_details import pds_get_patient_details
1011
from common.clients import logger
1112
from common.get_service_url import get_service_url
12-
from constants import DYNAMO_DB_TYPE_DESCRIPTORS, IMMUNISATION_TYPE, SPEC_VERSION, MnsNotificationPayload
13+
from constants import DYNAMO_DB_TYPE_DESCRIPTORS, IMMUNISATION_TYPE, SPEC_VERSION
1314

1415
IMMUNIZATION_ENV = os.getenv("IMMUNIZATION_ENV")
1516
IMMUNIZATION_BASE_PATH = os.getenv("IMMUNIZATION_BASE_PATH")

lambdas/shared/src/common/api_clients/constants.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import TypedDict
2+
13
"""Constants used by API clients"""
24

35

@@ -8,3 +10,28 @@ class Constants:
810
DEFAULT_API_CLIENTS_TIMEOUT = 5
911
API_CLIENTS_MAX_RETRIES = 2
1012
API_CLIENTS_BACKOFF_SECONDS = 0.5
13+
14+
15+
# Fields from the incoming SQS message that forms part of the base schema and filtering attributes for MNS notifications
16+
class FilteringData(TypedDict):
17+
"""MNS notification filtering attributes."""
18+
19+
generalpractitioner: str | None
20+
sourceorganisation: str
21+
sourceapplication: str
22+
subjectage: int
23+
immunisationtype: str
24+
action: str
25+
26+
27+
class MnsNotificationPayload(TypedDict):
28+
"""CloudEvents-compliant MNS notification payload."""
29+
30+
specversion: str
31+
id: str
32+
source: str
33+
type: str
34+
time: str
35+
subject: str
36+
dataref: str
37+
filtering: FilteringData

lambdas/shared/src/common/api_clients/mock_mns_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import boto3
55

6+
from common.api_clients.constants import MnsNotificationPayload
67
from common.clients import logger
78

89
REGION_NAME = os.getenv("AWS_REGION", "eu-west-2")
@@ -11,13 +12,10 @@
1112
class MockMnsService:
1213
def __init__(self, queue_url):
1314
self.queue_url = queue_url
14-
self.sqs_client = self._get_sqs_client()
15+
self.sqs_client = boto3.client("sqs", region_name=REGION_NAME)
1516
logger.info(f"MockMnsService initialized with queue: {queue_url}")
1617

17-
def _get_sqs_client(self):
18-
return boto3.client("sqs", region_name=REGION_NAME)
19-
20-
def publish_notification(self, mns_payload: dict) -> None:
18+
def publish_notification(self, mns_payload: MnsNotificationPayload) -> None:
2119
"""
2220
Send MNS notification payload to test SQS queue as fallback.
2321
Args: payload: MNS notification payload

0 commit comments

Comments
 (0)