Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions infrastructure/terraform/components/dl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ No requirements.
| <a name="module_pdm_mock"></a> [pdm\_mock](#module\_pdm\_mock) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_pdm_poll"></a> [pdm\_poll](#module\_pdm\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_pdm_uploader"></a> [pdm\_uploader](#module\_pdm\_uploader) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_print_analyser"></a> [print\_analyser](#module\_print\_analyser) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_print_status_handler"></a> [print\_status\_handler](#module\_print\_status\_handler) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_s3bucket_cf_logs"></a> [s3bucket\_cf\_logs](#module\_s3bucket\_cf\_logs) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
| <a name="module_s3bucket_file_safe"></a> [s3bucket\_file\_safe](#module\_s3bucket\_file\_safe) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
| <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 |
| <a name="module_s3bucket_non_pii_data"></a> [s3bucket\_non\_pii\_data](#module\_s3bucket\_non\_pii\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
| <a name="module_s3bucket_pii_data"></a> [s3bucket\_pii\_data](#module\_s3bucket\_pii\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip | n/a |
Expand All @@ -61,6 +63,7 @@ No requirements.
| <a name="module_sqs_mesh_download"></a> [sqs\_mesh\_download](#module\_sqs\_mesh\_download) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
| <a name="module_sqs_pdm_poll"></a> [sqs\_pdm\_poll](#module\_sqs\_pdm\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
| <a name="module_sqs_pdm_uploader"></a> [sqs\_pdm\_uploader](#module\_sqs\_pdm\_uploader) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
| <a name="module_sqs_print_analyser"></a> [sqs\_print\_analyser](#module\_sqs\_print\_analyser) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.30/terraform-sqs.zip | n/a |
| <a name="module_sqs_print_status_handler"></a> [sqs\_print\_status\_handler](#module\_sqs\_print\_status\_handler) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.30/terraform-sqs.zip | n/a |
| <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 |
| <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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "aws_cloudwatch_event_rule" "file_safe" {
name = "${local.csi}-file-safe"
description = "File safe event rule"
event_bus_name = aws_cloudwatch_event_bus.main.name

event_pattern = jsonencode({
"detail" : {
"type" : [
"uk.nhs.notify.digital.letters.print.file.safe.v1"
]
}
})
}

resource "aws_cloudwatch_event_target" "file_safe_print_analyser" {
rule = aws_cloudwatch_event_rule.file_safe.name
arn = module.sqs_print_analyser.sqs_queue_arn
event_bus_name = aws_cloudwatch_event_bus.main.name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "aws_lambda_event_source_mapping" "print_analyser" {
event_source_arn = module.sqs_print_analyser.sqs_queue_arn
function_name = module.print_analyser.function_name
batch_size = var.queue_batch_size
maximum_batching_window_in_seconds = var.queue_batch_window_seconds

function_response_types = [
"ReportBatchItemFailures"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module "print_analyser" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip"

function_name = "print-analyser"
description = "A function for processing file safe events"

aws_account_id = var.aws_account_id
component = local.component
environment = var.environment
project = var.project
region = var.region
group = var.group

log_retention_in_days = var.log_retention_in_days
kms_key_arn = module.kms.key_arn

iam_policy_document = {
body = data.aws_iam_policy_document.print_analyser.json
}

function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
function_code_base_path = local.aws_lambda_functions_dir_path
function_code_dir = "print-analyser/dist"
function_include_common = true
handler_function_name = "handler"
runtime = "nodejs22.x"
memory = 128
timeout = 60
log_level = var.log_level

force_lambda_code_deploy = var.force_lambda_code_deploy
enable_lambda_insights = false

log_destination_arn = local.log_destination_arn
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = {
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
}
}

data "aws_iam_policy_document" "print_analyser" {
statement {
sid = "PutEvents"
effect = "Allow"

actions = [
"events:PutEvents",
]

resources = [
aws_cloudwatch_event_bus.main.arn,
]
}

statement {
sid = "SQSPermissionsDLQs"
effect = "Allow"

actions = [
"sqs:SendMessage",
"sqs:SendMessageBatch",
]

resources = [
module.sqs_event_publisher_errors.sqs_queue_arn,
]
}

statement {
sid = "SQSPermissionsPrintAnalyserQueue"
effect = "Allow"

actions = [
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
]

resources = [
module.sqs_print_analyser.sqs_queue_arn,
]
}

statement {
sid = "S3PermissionsPrintAnalyserQueue"
effect = "Allow"

actions = [
"s3:GetObject",
]

resources = [
"${module.s3bucket_file_safe.arn}/*",
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
module "s3bucket_file_safe" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-s3bucket.zip"

name = "file-safe"

aws_account_id = var.aws_account_id
region = var.region
project = var.project
environment = var.environment
component = local.component

kms_key_arn = module.kms.key_arn

policy_documents = [data.aws_iam_policy_document.s3bucket_file_safe.json]

force_destroy = var.force_destroy

lifecycle_rules = [
{
enabled = true

expiration = {
days = "90"
}

noncurrent_version_transition = [
{
noncurrent_days = "30"
storage_class = "STANDARD_IA"
}
]

noncurrent_version_expiration = {
noncurrent_days = "90"
}

abort_incomplete_multipart_upload = {
days = "1"
}
}
]
}

data "aws_iam_policy_document" "s3bucket_file_safe" {
statement {
sid = "AllowManagedAccountsToList"
effect = "Allow"

actions = [
"s3:ListBucket",
]

resources = [
module.s3bucket_file_safe.arn,
]

principals {
type = "AWS"
identifiers = [
"arn:aws:iam::${var.aws_account_id}:root"
]
}
}

statement {
sid = "AllowManagedAccountsToGet"
effect = "Allow"

actions = [
"s3:GetObject",
]

resources = [
"${module.s3bucket_file_safe.arn}/*",
]

principals {
type = "AWS"
identifiers = [
"arn:aws:iam::${var.aws_account_id}:root"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module "sqs_print_analyser" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.30/terraform-sqs.zip"

aws_account_id = var.aws_account_id
component = local.component
environment = var.environment
project = var.project
region = var.region
name = "print-analyser"
sqs_kms_key_arn = module.kms.key_arn
visibility_timeout_seconds = 60
delay_seconds = 5
create_dlq = true
max_receive_count = 1
sqs_policy_overload = data.aws_iam_policy_document.sqs_print_analyser.json
}

data "aws_iam_policy_document" "sqs_print_analyser" {
statement {
sid = "AllowEventBridgeToSendMessage"
effect = "Allow"

principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}

actions = [
"sqs:SendMessage"
]

resources = [
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${local.csi}-print-analyser-queue"
]

condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = [aws_cloudwatch_event_rule.file_safe.arn]
}
}
}
5 changes: 5 additions & 0 deletions lambdas/print-analyser/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { baseJestConfig } from '../../jest.config.base';

const config = baseJestConfig;

export default config;
26 changes: 26 additions & 0 deletions lambdas/print-analyser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"dependencies": {
"aws-lambda": "^1.0.7",
"digital-letters-events": "^0.0.1",
"pdf-lib": "^1.17.1",
"utils": "^0.0.1"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
"@types/aws-lambda": "^8.10.155",
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.7",
"typescript": "^5.9.3"
},
"name": "nhs-notify-digital-letters-print-analyser",
"private": true,
"scripts": {
"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",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test:unit": "jest",
"typecheck": "tsc --noEmit"
},
"version": "0.0.1"
}
Loading
Loading