Skip to content

Commit 0559769

Browse files
committed
CCM-15676: initial code and infrastructure
1 parent 4474f70 commit 0559769

27 files changed

Lines changed: 1460 additions & 3 deletions

infrastructure/terraform/components/dl/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ No requirements.
7272
| <a name="module_mesh_download"></a> [mesh\_download](#module\_mesh\_download) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
7373
| <a name="module_mesh_poll"></a> [mesh\_poll](#module\_mesh\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
7474
| <a name="module_move_scanned_files"></a> [move\_scanned\_files](#module\_move\_scanned\_files) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
75+
| <a name="module_nhsapp_status_handler"></a> [nhsapp\_status\_handler](#module\_nhsapp\_status\_handler) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
7576
| <a name="module_pdm_mock"></a> [pdm\_mock](#module\_pdm\_mock) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
7677
| <a name="module_pdm_poll"></a> [pdm\_poll](#module\_pdm\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
7778
| <a name="module_pdm_uploader"></a> [pdm\_uploader](#module\_pdm\_uploader) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip | n/a |
@@ -95,6 +96,7 @@ No requirements.
9596
| <a name="module_sqs_mesh_acknowledge"></a> [sqs\_mesh\_acknowledge](#module\_sqs\_mesh\_acknowledge) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
9697
| <a name="module_sqs_mesh_download"></a> [sqs\_mesh\_download](#module\_sqs\_mesh\_download) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
9798
| <a name="module_sqs_move_scanned_files"></a> [sqs\_move\_scanned\_files](#module\_sqs\_move\_scanned\_files) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
99+
| <a name="module_sqs_nhsapp_status_handler"></a> [sqs\_nhsapp\_status\_handler](#module\_sqs\_nhsapp\_status\_handler) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
98100
| <a name="module_sqs_pdm_poll"></a> [sqs\_pdm\_poll](#module\_sqs\_pdm\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
99101
| <a name="module_sqs_pdm_uploader"></a> [sqs\_pdm\_uploader](#module\_sqs\_pdm\_uploader) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
100102
| <a name="module_sqs_print_analyser"></a> [sqs\_print\_analyser](#module\_sqs\_print\_analyser) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_cloudwatch_event_rule" "channel_status_published" {
2+
name = "${local.csi}-channel-status-published"
3+
description = "channel status PUBLISHED event rule"
4+
event_bus_name = aws_cloudwatch_event_bus.main.name
5+
6+
event_pattern = jsonencode({
7+
"detail" : {
8+
"type" : [
9+
"uk.nhs.notify.channel.status.PUBLISHED.v1"
10+
],
11+
}
12+
})
13+
}
14+
15+
resource "aws_cloudwatch_event_target" "sqs_nhsapp_status_handler_target" {
16+
rule = aws_cloudwatch_event_rule.channel_status_published.name
17+
arn = module.sqs_nhsapp_status_handler.sqs_queue_arn
18+
event_bus_name = aws_cloudwatch_event_bus.main.name
19+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
module "nhsapp_status_handler" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-lambda.zip"
3+
4+
function_name = "nhsapp-status-handler"
5+
description = "A function for handling NHS app status"
6+
7+
aws_account_id = var.aws_account_id
8+
component = local.component
9+
environment = var.environment
10+
project = var.project
11+
region = var.region
12+
group = var.group
13+
14+
log_retention_in_days = var.log_retention_in_days
15+
kms_key_arn = module.kms.key_arn
16+
17+
iam_policy_document = {
18+
body = data.aws_iam_policy_document.nhsapp_status_handler.json
19+
}
20+
21+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
22+
function_code_base_path = local.aws_lambda_functions_dir_path
23+
function_code_dir = "nhsapp-status-handler-lambda/dist"
24+
function_include_common = true
25+
handler_function_name = "handler"
26+
runtime = "nodejs22.x"
27+
memory = 256
28+
timeout = var.lambda_timeout_seconds
29+
log_level = var.log_level
30+
31+
force_lambda_code_deploy = var.force_lambda_code_deploy
32+
enable_lambda_insights = false
33+
34+
log_destination_arn = local.log_destination_arn
35+
log_subscription_role_arn = local.acct.log_subscription_role_arn
36+
37+
lambda_env_vars = {
38+
"TTL_TABLE_NAME" = aws_dynamodb_table.ttl.name
39+
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
40+
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
41+
}
42+
}
43+
44+
data "aws_iam_policy_document" "nhsapp_status_handler" {
45+
statement {
46+
sid = "AllowTtlDynamoAccess"
47+
effect = "Allow"
48+
49+
actions = [
50+
"dynamodb:PutItem",
51+
]
52+
53+
resources = [
54+
aws_dynamodb_table.ttl.arn,
55+
]
56+
}
57+
58+
statement {
59+
sid = "KMSPermissions"
60+
effect = "Allow"
61+
62+
actions = [
63+
"kms:Decrypt",
64+
"kms:GenerateDataKey",
65+
]
66+
67+
resources = [
68+
module.kms.key_arn,
69+
]
70+
}
71+
72+
statement {
73+
sid = "SQSPermissionsNhsappStatusHandlerQueue"
74+
effect = "Allow"
75+
76+
actions = [
77+
"sqs:ReceiveMessage",
78+
"sqs:DeleteMessage",
79+
"sqs:GetQueueAttributes",
80+
"sqs:GetQueueUrl",
81+
]
82+
83+
resources = [
84+
module.sqs_nhsapp_status_handler.sqs_queue_arn,
85+
]
86+
}
87+
88+
statement {
89+
sid = "PutEvents"
90+
effect = "Allow"
91+
92+
actions = [
93+
"events:PutEvents",
94+
]
95+
96+
resources = [
97+
aws_cloudwatch_event_bus.main.arn,
98+
]
99+
}
100+
101+
statement {
102+
sid = "SQSPermissionsEventPublisherDLQ"
103+
effect = "Allow"
104+
105+
actions = [
106+
"sqs:SendMessage",
107+
"sqs:SendMessageBatch",
108+
]
109+
110+
resources = [
111+
module.sqs_event_publisher_errors.sqs_queue_arn,
112+
]
113+
}
114+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module "sqs_nhsapp_status_handler" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip"
3+
4+
aws_account_id = var.aws_account_id
5+
component = local.component
6+
environment = var.environment
7+
project = var.project
8+
region = var.region
9+
name = "nhsapp-status-handler"
10+
sqs_kms_key_arn = module.kms.key_arn
11+
visibility_timeout_seconds = var.sqs_visibility_timeout_seconds
12+
create_dlq = true
13+
max_receive_count = var.sqs_max_receive_count
14+
sqs_policy_overload = data.aws_iam_policy_document.sqs_nhsapp_status_handler.json
15+
}
16+
17+
data "aws_iam_policy_document" "sqs_nhsapp_status_handler" {
18+
statement {
19+
sid = "AllowEventBridgeToSendMessage"
20+
effect = "Allow"
21+
22+
principals {
23+
type = "Service"
24+
identifiers = ["events.amazonaws.com"]
25+
}
26+
27+
actions = [
28+
"sqs:SendMessage"
29+
]
30+
31+
resources = [
32+
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${local.csi}-nhsapp-status-handler-queue"
33+
]
34+
35+
condition {
36+
test = "ArnLike"
37+
variable = "aws:SourceArn"
38+
values = [aws_cloudwatch_event_rule.channel_status_published.arn]
39+
}
40+
}
41+
}

lambdas/core-notifier-lambda/src/__tests__/domain/mapper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('mapper', () => {
6363
type: 'Message',
6464
attributes: {
6565
routingPlanId: 'routing-config-123',
66-
messageReference: 'msg-ref-123',
66+
messageReference: 'test-sender-id_msg-ref-123',
6767
billingReference: 'test-sender-id',
6868
recipient: {
6969
nhsNumber: '9999999999',

lambdas/core-notifier-lambda/src/domain/mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function mapPdmEventToSingleMessageRequest(
3131
type: 'Message',
3232
attributes: {
3333
routingPlanId: sender.routingConfigId!,
34-
messageReference,
34+
messageReference: `${sender.senderId}_${messageReference}`,
3535
billingReference: sender.senderId,
3636
recipient: {
3737
nhsNumber: data.nhsNumber,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { baseJestConfig } from '../../jest.config.base';
2+
3+
const config = baseJestConfig;
4+
5+
export default config;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"dependencies": {
3+
"@aws-sdk/lib-dynamodb": "^3.908.0",
4+
"digital-letters-events": "^0.0.1",
5+
"utils": "^0.0.1",
6+
"zod": "^4.3.6"
7+
},
8+
"devDependencies": {
9+
"@tsconfig/node22": "^22.0.2",
10+
"@types/aws-lambda": "^8.10.155",
11+
"@types/jest": "^29.5.14",
12+
"jest": "^29.7.0",
13+
"typescript": "^5.9.3"
14+
},
15+
"name": "nhs-notify-digital-letters-nhsapp-status-handler",
16+
"private": true,
17+
"scripts": {
18+
"lambda-build": "rm -rf dist && npx esbuild --bundle --minify --sourcemap --target=es2020 --platform=node --loader:.node=file --entry-names=[name] --outdir=dist src/index.ts",
19+
"lint": "eslint .",
20+
"lint:fix": "eslint . --fix",
21+
"test:unit": "jest",
22+
"typecheck": "tsc --noEmit"
23+
},
24+
"version": "0.0.1"
25+
}

0 commit comments

Comments
 (0)