Skip to content

Commit e56bd73

Browse files
committed
CCM-12614: add sqs queue and rule
1 parent aac68f4 commit e56bd73

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

infrastructure/terraform/components/dl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ No requirements.
4545
| <a name="module_s3bucket_letters"></a> [s3bucket\_letters](#module\_s3bucket\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
4646
| <a name="module_s3bucket_static_assets"></a> [s3bucket\_static\_assets](#module\_s3bucket\_static\_assets) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
4747
| <a name="module_sqs_event_publisher_errors"></a> [sqs\_event\_publisher\_errors](#module\_sqs\_event\_publisher\_errors) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
48+
| <a name="module_sqs_poll_pdm"></a> [sqs\_poll\_pdm](#module\_sqs\_poll\_pdm) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
4849
| <a name="module_sqs_ttl"></a> [sqs\_ttl](#module\_sqs\_ttl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
4950
| <a name="module_sqs_ttl_handle_expiry_errors"></a> [sqs\_ttl\_handle\_expiry\_errors](#module\_sqs\_ttl\_handle\_expiry\_errors) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
5051
| <a name="module_ttl_create"></a> [ttl\_create](#module\_ttl\_create) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
resource "aws_cloudwatch_event_rule" "pdm_resource_submitted" {
2+
name = "${local.csi}-pdm-resource-submitted"
3+
description = "PDM resource submitted 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.digital.letters.pdm.resource.submitted.v1"
10+
]
11+
}
12+
})
13+
}
14+
15+
resource "aws_cloudwatch_event_target" "pdm_resource_submitted" {
16+
rule = aws_cloudwatch_event_rule.pdm_resource_submitted.name
17+
arn = module.sqs_poll_pdm.sqs_queue_arn
18+
target_id = "pdm-resource-submitted-target"
19+
event_bus_name = aws_cloudwatch_event_bus.main.name
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "aws_lambda_event_source_mapping" "poll_pdm_lambda" {
2+
event_source_arn = module.sqs_poll_pdm.sqs_queue_arn
3+
function_name = module.poll_pdm.function_name
4+
batch_size = var.queue_batch_size
5+
maximum_batching_window_in_seconds = var.queue_batch_window_seconds
6+
7+
function_response_types = [
8+
"ReportBatchItemFailures"
9+
]
10+
}

infrastructure/terraform/components/dl/module_lambda_poll_pdm.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module "poll_pdm" {
2525
handler_function_name = "handler"
2626
runtime = "nodejs22.x"
2727
memory = 128
28-
timeout = 360
28+
timeout = 60
2929
log_level = var.log_level
3030

3131
force_lambda_code_deploy = var.force_lambda_code_deploy
@@ -70,4 +70,19 @@ data "aws_iam_policy_document" "poll_pdm_lambda" {
7070
module.sqs_event_publisher_errors.sqs_queue_arn,
7171
]
7272
}
73+
statement {
74+
sid = "SQSPermissionsPollPdmQueue"
75+
effect = "Allow"
76+
77+
actions = [
78+
"sqs:ReceiveMessage",
79+
"sqs:DeleteMessage",
80+
"sqs:GetQueueAttributes",
81+
"sqs:GetQueueUrl",
82+
]
83+
84+
resources = [
85+
module.sqs_poll_pdm.sqs_queue_arn,
86+
]
87+
}
7388
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module "sqs_poll_pdm" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/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 = "poll-pdm"
10+
sqs_kms_key_arn = module.kms.key_arn
11+
visibility_timeout_seconds = 60
12+
delay_seconds = 5
13+
create_dlq = true
14+
sqs_policy_overload = data.aws_iam_policy_document.sqs_poll_pdm.json
15+
}
16+
17+
data "aws_iam_policy_document" "sqs_poll_pdm" {
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}:${var.project}-${var.environment}-${local.component}-poll-pdm-queue"
33+
]
34+
}
35+
}

0 commit comments

Comments
 (0)