-
Notifications
You must be signed in to change notification settings - Fork 4
VED:1099: Create Test SQS Queue for MNS #1268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Akol125
merged 15 commits into
VED-982-Notification-Lambda-MNS
from
VED-1099-Temp-Mns-Sqs-Queue
Mar 6, 2026
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
10730f9
create temporary sqs queue for mns publish notification
motola d236e98
remove space in terraform
motola 8b54902
maintain terraform hcl and use imms-vacc-1
motola 315ca08
use queue url to trigger notification to SQS
motola e6a22c9
added outputs and message retention
motola dcbde02
make output reference module
motola fc31344
missing output in child module
motola 6933833
use factory pattern for publishing notification
motola 55c18d3
test for mock_mns_service
motola e0c2134
enable test queue only in dev
motola 337e745
change count to zero in mns_publisher lambda
motola 0657096
terraform ternary tweaks for mns publish
motola 8f8fc87
terraform and code changes on mns_publish
motola 0520b95
add type hiniting
motola 163082a
move string literal to constant
motola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
infrastructure/instance/modules/mns_publisher/sqs_test_publish_mns.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Main queue for MNS notification testing | ||
| resource "aws_sqs_queue" "mns_test_notification" { | ||
| name = "${var.mns_test_notifcation_name_prefix}-queue" | ||
|
dlzhry2nhs marked this conversation as resolved.
Outdated
|
||
| fifo_queue = false | ||
| kms_master_key_id = aws_kms_key.mns_outbound_events.arn | ||
| visibility_timeout_seconds = 300 | ||
| } | ||
|
|
||
|
|
||
| data "aws_iam_policy_document" "mns_test_notification_sqs_policy" { | ||
| statement { | ||
| sid = "mns-test-notification-allow-lambda-access" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "AWS" | ||
| identifiers = [aws_iam_role.mns_publisher_lambda_exec_role.arn] | ||
|
dlzhry2nhs marked this conversation as resolved.
|
||
| } | ||
|
|
||
| actions = [ | ||
| "sqs:SendMessage", | ||
| ] | ||
|
|
||
| resources = [ | ||
| aws_sqs_queue.mns_test_notification.arn | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_sqs_queue_policy" "mns_test_notification_sqs" { | ||
| queue_url = aws_sqs_queue.mns_test_notification.id | ||
| policy = data.aws_iam_policy_document.mns_test_notification_sqs_policy.json | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
edhall-nhs marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import json | ||
| import os | ||
|
|
||
| import boto3 | ||
|
|
||
| from common.clients import logger | ||
|
|
||
| MNS_TEST_QUEUE_URL = os.getenv("MNS_TEST_QUEUE_URL") | ||
| sqs_client = boto3.client("sqs", region_name="eu-west-2") | ||
|
|
||
|
|
||
| def send_notification_to_test_queue(mns_payload: dict) -> None: | ||
| """ | ||
| Send MNS notification payload to test SQS queue as fallback. | ||
| Args: payload: MNS notification payload | ||
| """ | ||
| if not MNS_TEST_QUEUE_URL: | ||
| logger.error("MNS_TEST_QUEUE_URL environment variable is not set") | ||
| return | ||
|
|
||
| try: | ||
| response = sqs_client.send_message( | ||
| QueueUrl=MNS_TEST_QUEUE_URL, | ||
| MessageBody=json.dumps(mns_payload), | ||
| MessageAttributes={"source": {"StringValue": "mns-publisher-lambda", "DataType": "String"}}, | ||
| ) | ||
| logger.info("Successfully sent notification to test queue", extra={"message_id": response["MessageId"]}) | ||
| except Exception: | ||
| logger.exception("Failed to send to test SQS queue") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import json | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| import boto3 | ||
| from moto import mock_aws | ||
|
|
||
| from mns_test_queue import send_notification_to_test_queue | ||
|
|
||
|
|
||
| @mock_aws | ||
| class TestMnsSqsQueue(unittest.TestCase): | ||
|
Akol125 marked this conversation as resolved.
Outdated
|
||
| def setUp(self): | ||
| self.sqs = boto3.client("sqs", region_name="eu-west-2") | ||
| response = self.sqs.create_queue(QueueName="mns-test-notifications-int") | ||
| self.queue_url = response["QueueUrl"] | ||
|
|
||
| self.mns_payload = { | ||
| "specversion": "1.0", | ||
| "id": "236a1d4a-5d69-4fa9-9c7f-e72bf505aa5b", | ||
| "source": "https://int.api.service.nhs.uk/immunisation-fhir-api", | ||
| "type": "imms-vaccinations-2", | ||
| "time": "20260212T174437+00:00", | ||
| "subject": "9481152782", | ||
| "dataref": "https://int.api.service.nhs.uk/immunisation-fhir-api/Immunization/d058014c-b0fd-4471-8db9-3316175eb825", | ||
| "filtering": { | ||
| "generalpractitioner": "Y12345", | ||
| "sourceorganisation": "B0C4P", | ||
| "sourceapplication": "TPP", | ||
| "subjectage": 21, | ||
| "immunisationtype": "HIB", | ||
| "action": "CREATE", | ||
| }, | ||
| } | ||
|
|
||
| def test_send_notification_to_queue_success(self): | ||
| """Test successful send to SQS queue with complete payload.""" | ||
| with patch("mns_test_queue.MNS_TEST_QUEUE_URL", self.queue_url): | ||
| send_notification_to_test_queue(self.mns_payload) | ||
|
|
||
| messages = self.sqs.receive_message( | ||
| QueueUrl=self.queue_url, MaxNumberOfMessages=1, MessageAttributeNames=["All"] | ||
| ) | ||
|
|
||
| self.assertIn("Messages", messages) | ||
| self.assertEqual(len(messages["Messages"]), 1) | ||
|
|
||
| # Verify message body | ||
| mns_payload = json.loads(messages["Messages"][0]["Body"]) | ||
| attributes = messages["Messages"][0]["MessageAttributes"] | ||
| self.assertEqual(attributes["source"]["StringValue"], "mns-publisher-lambda") | ||
|
|
||
| self.assertEqual(mns_payload["subject"], "9481152782") | ||
| self.assertEqual(mns_payload["filtering"]["generalpractitioner"], "Y12345") | ||
| self.assertEqual(mns_payload["filtering"]["sourceorganisation"], "B0C4P") | ||
| self.assertEqual(mns_payload["filtering"]["sourceapplication"], "TPP") | ||
| self.assertEqual(mns_payload["filtering"]["immunisationtype"], "HIB") | ||
| self.assertEqual(mns_payload["filtering"]["action"], "CREATE") | ||
| self.assertEqual(mns_payload["filtering"]["subjectage"], 21) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.