Skip to content

Commit f3be2ac

Browse files
committed
CCM-12613: Upload to PDM component
1 parent 93bd7c5 commit f3be2ac

33 files changed

+1871
-17
lines changed

infrastructure/terraform/components/dl/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ No requirements.
1111
|------|-------------|------|---------|:--------:|
1212
| <a name="input_apim_auth_token_schedule"></a> [apim\_auth\_token\_schedule](#input\_apim\_auth\_token\_schedule) | Schedule to renew the APIM auth token | `string` | `"rate(9 minutes)"` | no |
1313
| <a name="input_apim_auth_token_url"></a> [apim\_auth\_token\_url](#input\_apim\_auth\_token\_url) | URL to generate an APIM auth token | `string` | `"https://int.api.service.nhs.uk/oauth2/token"` | no |
14-
| <a name="input_apim_base_url"></a> [apim\_base\_url](#input\_apim\_base\_url) | The URL used to send requests to Notify and PDM | `string` | `"https://sandbox.api.service.nhs.uk"` | no |
14+
| <a name="input_apim_base_url"></a> [apim\_base\_url](#input\_apim\_base\_url) | The URL used to send requests to Notify and PDM | `string` | `"https://int.api.service.nhs.uk"` | no |
1515
| <a name="input_apim_keygen_schedule"></a> [apim\_keygen\_schedule](#input\_apim\_keygen\_schedule) | Schedule to refresh key pairs if necessary | `string` | `"cron(0 14 * * ? *)"` | no |
1616
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | The AWS Account ID (numeric) | `string` | n/a | yes |
1717
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"dl"` | no |
@@ -46,9 +46,11 @@ No requirements.
4646
| <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 |
4747
| <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 |
4848
| <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 |
49+
| <a name="module_sqs_upload_to_pdm"></a> [sqs\_upload\_to\_pdm](#module\_sqs\_upload\_to\_pdm) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
4950
| <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 |
5051
| <a name="module_ttl_handle_expiry"></a> [ttl\_handle\_expiry](#module\_ttl\_handle\_expiry) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
5152
| <a name="module_ttl_poll"></a> [ttl\_poll](#module\_ttl\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
53+
| <a name="module_upload_to_pdm"></a> [upload\_to\_pdm](#module\_upload\_to\_pdm) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
5254
## Outputs
5355

5456
| Name | Description |

infrastructure/terraform/components/dl/cloudwatch_event_rule_mesh_inbox_message_downloaded.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ resource "aws_cloudwatch_event_rule" "mesh_inbox_message_downloaded" {
1515
})
1616
}
1717

18-
resource "aws_cloudwatch_event_target" "mesh_inbox_message_downloaded" {
18+
resource "aws_cloudwatch_event_target" "create-ttl-target" {
1919
rule = aws_cloudwatch_event_rule.mesh_inbox_message_downloaded.name
2020
arn = module.sqs_ttl.sqs_queue_arn
21-
target_id = "mesh-inbox-message-downloaded-target"
21+
target_id = "create-ttl-target"
22+
event_bus_name = aws_cloudwatch_event_bus.main.name
23+
}
24+
25+
resource "aws_cloudwatch_event_target" "upload-to-pdm-target" {
26+
rule = aws_cloudwatch_event_rule.mesh_inbox_message_downloaded.name
27+
arn = module.sqs_upload_to_pdm.sqs_queue_arn
28+
target_id = "upload-to-pdm-target"
2229
event_bus_name = aws_cloudwatch_event_bus.main.name
2330
}
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" "sqs_upload_to_pdm_lambda" {
2+
event_source_arn = module.sqs_upload_to_pdm.sqs_queue_arn
3+
function_name = module.upload_to_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+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
module "upload_to_pdm" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
3+
4+
function_name = "upload-to-pdm"
5+
description = "A function to upload documents to PDM"
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.upload_to_pdm_lambda.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 = "upload-to-pdm-lambda/dist"
24+
function_include_common = true
25+
handler_function_name = "handler"
26+
runtime = "nodejs22.x"
27+
memory = 128
28+
timeout = 60
29+
log_level = var.log_level
30+
31+
force_lambda_code_deploy = var.force_lambda_code_deploy
32+
enable_lambda_insights = false
33+
34+
send_to_firehose = true
35+
log_destination_arn = local.log_destination_arn
36+
log_subscription_role_arn = local.acct.log_subscription_role_arn
37+
38+
lambda_env_vars = {
39+
"APIM_BASE_URL" = var.apim_base_url
40+
"APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.apim_access_token_ssm_parameter_name
41+
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
42+
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
43+
}
44+
}
45+
46+
data "aws_iam_policy_document" "upload_to_pdm_lambda" {
47+
statement {
48+
sid = "AllowSSMParam"
49+
effect = "Allow"
50+
51+
actions = [
52+
"ssm:GetParameter",
53+
"ssm:GetParameters",
54+
"ssm:GetParametersByPath"
55+
]
56+
57+
resources = [
58+
"arn:aws:ssm:${var.region}:${var.aws_account_id}:parameter/${var.component}/${var.environment}/apim/*"
59+
]
60+
}
61+
62+
statement {
63+
sid = "AllowS3Get"
64+
effect = "Allow"
65+
66+
actions = [
67+
"s3:GetObject"
68+
]
69+
70+
resources = [
71+
"${module.s3bucket_letters.arn}/*"
72+
]
73+
}
74+
75+
statement {
76+
sid = "KMSPermissions"
77+
effect = "Allow"
78+
79+
actions = [
80+
"kms:Decrypt",
81+
"kms:GenerateDataKey",
82+
]
83+
84+
resources = [
85+
module.kms.key_arn,
86+
]
87+
}
88+
89+
statement {
90+
sid = "SQSPermissionsUploadToPdmQueue"
91+
effect = "Allow"
92+
93+
actions = [
94+
"sqs:ReceiveMessage",
95+
"sqs:DeleteMessage",
96+
"sqs:GetQueueAttributes",
97+
"sqs:GetQueueUrl",
98+
]
99+
100+
resources = [
101+
module.sqs_upload_to_pdm.sqs_queue_arn,
102+
]
103+
}
104+
105+
statement {
106+
sid = "PutEvents"
107+
effect = "Allow"
108+
109+
actions = [
110+
"events:PutEvents",
111+
]
112+
113+
resources = [
114+
aws_cloudwatch_event_bus.main.arn,
115+
]
116+
}
117+
118+
statement {
119+
sid = "SQSPermissionsEventPublisherDLQ"
120+
effect = "Allow"
121+
122+
actions = [
123+
"sqs:SendMessage",
124+
"sqs:SendMessageBatch",
125+
]
126+
127+
resources = [
128+
module.sqs_event_publisher_errors.sqs_queue_arn,
129+
]
130+
}
131+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module "sqs_upload_to_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 = "upload-to-pdm"
10+
11+
sqs_kms_key_arn = module.kms.key_arn
12+
13+
visibility_timeout_seconds = 60
14+
15+
create_dlq = true
16+
17+
sqs_policy_overload = data.aws_iam_policy_document.sqs_upload_to_pdm.json
18+
}
19+
20+
data "aws_iam_policy_document" "sqs_upload_to_pdm" {
21+
statement {
22+
sid = "AllowEventBridgeToSendMessage"
23+
effect = "Allow"
24+
25+
principals {
26+
type = "Service"
27+
identifiers = ["events.amazonaws.com"]
28+
}
29+
30+
actions = [
31+
"sqs:SendMessage"
32+
]
33+
34+
resources = [
35+
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${local.component}-upload-to-pdm-queue"
36+
]
37+
}
38+
}

infrastructure/terraform/components/dl/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ variable "ttl_poll_schedule" {
119119
variable "apim_base_url" {
120120
type = string
121121
description = "The URL used to send requests to Notify and PDM"
122-
default = "https://sandbox.api.service.nhs.uk"
122+
default = "https://int.api.service.nhs.uk"
123123
}
124124

125125
variable "apim_auth_token_url" {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { baseJestConfig } from '../../jest.config.base';
2+
3+
const config = baseJestConfig;
4+
5+
config.coveragePathIgnorePatterns = ['/__tests__/', 'cli.ts'];
6+
config.coverageThreshold = {
7+
global: {
8+
branches: 90,
9+
functions: 100,
10+
lines: 90,
11+
statements: -10,
12+
},
13+
};
14+
15+
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+
"axios": "^1.13.2",
5+
"utils": "^0.0.1",
6+
"zod": "^4.1.12"
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-upload-to-pdm-lambda",
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)