Skip to content

Commit 2cd24d0

Browse files
CCM-7940: Event publisher lambda
1 parent b1b39ab commit 2cd24d0

File tree

57 files changed

+1198
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1198
-140
lines changed

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react": "^19.0.0",
2020
"react-dom": "^19.0.0",
2121
"react-idle-timer": "^5.7.2",
22-
"zod": "^3.24.2"
22+
"zod": "^4.0.5"
2323
},
2424
"devDependencies": {
2525
"@testing-library/jest-dom": "^6.6.3",

infrastructure/terraform/components/app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
| <a name="module_amplify_branch"></a> [amplify\_branch](#module\_amplify\_branch) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/amp_branch | v1.0.0 |
5454
| <a name="module_backend_api"></a> [backend\_api](#module\_backend\_api) | ../../modules/backend-api | n/a |
5555
| <a name="module_download_authorizer_lambda"></a> [download\_authorizer\_lambda](#module\_download\_authorizer\_lambda) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.13 |
56-
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/eventpub | v1.0.13 |
56+
| <a name="module_eventpub"></a> [eventpub](#module\_eventpub) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/eventpub | v2.0.16 |
5757
| <a name="module_kms"></a> [kms](#module\_kms) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/kms | v1.0.8 |
5858
| <a name="module_kms_us_east_1"></a> [kms\_us\_east\_1](#module\_kms\_us\_east\_1) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/kms | v1.0.8 |
5959
| <a name="module_nhse_backup_vault"></a> [nhse\_backup\_vault](#module\_nhse\_backup\_vault) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/aws-backup-source | v2.0.12 |

infrastructure/terraform/components/app/module_backend_api.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ module "backend_api" {
3131
email_domain = module.ses.domain
3232
template_submitted_sender_email_address = "template-submitted@${module.ses.domain}"
3333
proof_requested_sender_email_address = "proof-requested@${module.ses.domain}"
34+
35+
sns_topic_arn = module.eventpub.sns_topic.arn
3436
}

infrastructure/terraform/components/app/module_eventpub.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "eventpub" {
2-
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/eventpub?ref=v1.0.13"
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/eventpub?ref=v2.0.16"
33

44
name = "eventpub"
55

infrastructure/terraform/modules/backend-api/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ No requirements.
3232
| <a name="input_proof_requested_sender_email_address"></a> [proof\_requested\_sender\_email\_address](#input\_proof\_requested\_sender\_email\_address) | Proof requested sender email address | `string` | n/a | yes |
3333
| <a name="input_region"></a> [region](#input\_region) | The AWS Region | `string` | n/a | yes |
3434
| <a name="input_send_to_firehose"></a> [send\_to\_firehose](#input\_send\_to\_firehose) | Flag indicating whether logs should be sent to firehose | `bool` | n/a | yes |
35+
| <a name="input_sns_topic_arn"></a> [sns\_topic\_arn](#input\_sns\_topic\_arn) | SNS topic ARN | `string` | `null` | no |
3536
| <a name="input_template_submitted_sender_email_address"></a> [template\_submitted\_sender\_email\_address](#input\_template\_submitted\_sender\_email\_address) | Template submitted sender email address | `string` | n/a | yes |
3637
## Modules
3738

@@ -45,6 +46,7 @@ No requirements.
4546
| <a name="module_get_template_lambda"></a> [get\_template\_lambda](#module\_get\_template\_lambda) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
4647
| <a name="module_lambda_copy_scanned_object_to_internal"></a> [lambda\_copy\_scanned\_object\_to\_internal](#module\_lambda\_copy\_scanned\_object\_to\_internal) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
4748
| <a name="module_lambda_delete_failed_scanned_object"></a> [lambda\_delete\_failed\_scanned\_object](#module\_lambda\_delete\_failed\_scanned\_object) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
49+
| <a name="module_lambda_event_publisher"></a> [lambda\_event\_publisher](#module\_lambda\_event\_publisher) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
4850
| <a name="module_lambda_process_proof"></a> [lambda\_process\_proof](#module\_lambda\_process\_proof) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
4951
| <a name="module_lambda_set_file_virus_scan_status_for_upload"></a> [lambda\_set\_file\_virus\_scan\_status\_for\_upload](#module\_lambda\_set\_file\_virus\_scan\_status\_for\_upload) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
5052
| <a name="module_lambda_sftp_poll"></a> [lambda\_sftp\_poll](#module\_lambda\_sftp\_poll) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
@@ -56,7 +58,7 @@ No requirements.
5658
| <a name="module_s3bucket_internal"></a> [s3bucket\_internal](#module\_s3bucket\_internal) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
5759
| <a name="module_s3bucket_quarantine"></a> [s3bucket\_quarantine](#module\_s3bucket\_quarantine) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
5860
| <a name="module_sqs_sftp_upload"></a> [sqs\_sftp\_upload](#module\_sqs\_sftp\_upload) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
59-
| <a name="module_sqs_template_mgmt_events"></a> [sqs\_template\_mgmt\_events](#module\_sqs\_template\_mgmt\_events) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.8 |
61+
| <a name="module_sqs_template_mgmt_events"></a> [sqs\_template\_mgmt\_events](#module\_sqs\_template\_mgmt\_events) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.15 |
6062
| <a name="module_sqs_template_table_events_pipe_dlq"></a> [sqs\_template\_table\_events\_pipe\_dlq](#module\_sqs\_template\_table\_events\_pipe\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.8 |
6163
| <a name="module_sqs_validate_letter_template_files"></a> [sqs\_validate\_letter\_template\_files](#module\_sqs\_validate\_letter\_template\_files) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
6264
| <a name="module_submit_template_lambda"></a> [submit\_template\_lambda](#module\_submit\_template\_lambda) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.4 |
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
module "lambda_event_publisher" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda?ref=v2.0.4"
3+
4+
project = var.project
5+
environment = var.environment
6+
component = var.component
7+
aws_account_id = var.aws_account_id
8+
region = var.region
9+
10+
kms_key_arn = var.kms_key_arn
11+
12+
function_name = "event-publisher"
13+
14+
function_module_name = "event-publisher"
15+
handler_function_name = "handler"
16+
description = "Lambda that accepts events from the dynamodb stream and publishes them to SNS"
17+
18+
memory = 512
19+
timeout = 20
20+
runtime = "nodejs20.x"
21+
22+
log_retention_in_days = var.log_retention_in_days
23+
iam_policy_document = {
24+
body = data.aws_iam_policy_document.event_publisher.json
25+
}
26+
27+
lambda_env_vars = {
28+
SNS_TOPIC_ARN = coalesce(var.sns_topic_arn, aws_sns_topic.main.arn)
29+
TEMPLATES_TABLE_NAME = aws_dynamodb_table.templates.name
30+
EVENT_SOURCE = "//notify.nhs.uk/${var.component}/${var.group}/${var.environment}"
31+
}
32+
33+
function_s3_bucket = var.function_s3_bucket
34+
function_code_base_path = local.lambdas_dir
35+
function_code_dir = "event-publisher/dist"
36+
37+
send_to_firehose = var.send_to_firehose
38+
log_destination_arn = var.log_destination_arn
39+
log_subscription_role_arn = var.log_subscription_role_arn
40+
}
41+
42+
resource "aws_lambda_event_source_mapping" "event_publisher" {
43+
event_source_arn = module.sqs_template_mgmt_events.sqs_queue_arn
44+
function_name = module.lambda_event_publisher.function_name
45+
batch_size = 5
46+
maximum_batching_window_in_seconds = 0
47+
function_response_types = [
48+
"ReportBatchItemFailures"
49+
]
50+
51+
scaling_config {
52+
maximum_concurrency = 5
53+
}
54+
}
55+
56+
data "aws_iam_policy_document" "event_publisher" {
57+
statement {
58+
sid = "AllowSNS"
59+
effect = "Allow"
60+
61+
actions = [
62+
"sns:Publish",
63+
]
64+
65+
resources = [
66+
coalesce(var.sns_topic_arn, aws_sns_topic.main.arn)
67+
]
68+
}
69+
70+
statement {
71+
sid = "AllowSQSDLQ"
72+
effect = "Allow"
73+
74+
actions = [
75+
"sqs:SendMessage",
76+
]
77+
78+
resources = [
79+
module.sqs_template_mgmt_events.sqs_dlq_arn,
80+
]
81+
}
82+
83+
statement {
84+
sid = "AllowSQS"
85+
effect = "Allow"
86+
87+
actions = [
88+
"sqs:ReceiveMessage",
89+
"sqs:DeleteMessage",
90+
"sqs:GetQueueAttributes",
91+
"sqs:ChangeMessageVisibility",
92+
]
93+
94+
resources = [
95+
module.sqs_template_mgmt_events.sqs_queue_arn,
96+
]
97+
}
98+
99+
statement {
100+
sid = "AllowKMS"
101+
effect = "Allow"
102+
103+
actions = [
104+
"kms:Decrypt",
105+
"kms:DescribeKey",
106+
"kms:Encrypt",
107+
"kms:GenerateDataKey*",
108+
"kms:ReEncrypt*",
109+
]
110+
111+
resources = [
112+
var.kms_key_arn,
113+
]
114+
}
115+
}

infrastructure/terraform/modules/backend-api/module_sqs_template_mgmt_events.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "sqs_template_mgmt_events" {
2-
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs?ref=v2.0.8"
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs?ref=v2.0.15"
33

44
aws_account_id = var.aws_account_id
55
component = var.component
@@ -9,4 +9,5 @@ module "sqs_template_mgmt_events" {
99
name = "template-mgmt-events"
1010
fifo_queue = true
1111
sqs_kms_key_arn = var.kms_key_arn
12+
create_dlq = true
1213
}

infrastructure/terraform/modules/backend-api/pipes_pipe_template_table_events.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ resource "aws_pipes_pipe" "template_table_events" {
2222
}
2323

2424
target_parameters {
25+
input_template = "{\"dynamodb\": <$.dynamodb>,\"eventID\": <$.eventID>,\"eventName\": <$.eventName>,\"eventSource\": <$.eventSource>,\"tableName\": \"${aws_dynamodb_table.templates.name}\"}"
26+
2527
sqs_queue_parameters {
2628
message_group_id = "$.dynamodb.Keys.id.S"
2729
message_deduplication_id = "$.eventID"

infrastructure/terraform/modules/backend-api/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ variable "proof_requested_sender_email_address" {
143143
type = string
144144
description = "Proof requested sender email address"
145145
}
146+
147+
variable "sns_topic_arn" {
148+
type = string
149+
description = "SNS topic ARN"
150+
default = null
151+
}

lambdas/authorizer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"jwks-rsa": "^3.2.0",
66
"jwt-decode": "^4.0.0",
77
"nhs-notify-web-template-management-utils": "^0.0.1",
8-
"zod": "^3.24.2"
8+
"zod": "^4.0.5"
99
},
1010
"devDependencies": {
1111
"@swc/core": "^1.11.13",

0 commit comments

Comments
 (0)