Skip to content

Commit 7c9a282

Browse files
committed
Merge branch 'refs/heads/main' into feature/CCM-12352-refactor-helpers-and-datastore
# Conflicts: # lambdas/api-handler/src/infrastructure/letter-repo-factory.ts # lambdas/api-handler/src/services/__tests__/letter-operations.test.ts
2 parents e3c8315 + 54b0fc2 commit 7c9a282

31 files changed

+1421
-475
lines changed

docs/assets/diagrams/phase1.png

-3.32 KB
Loading

docs/collections/_consumers/acceptance.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,13 @@ Your MI submissions accurately match the letters you've processed.
511511
**Endpoints:**
512512

513513
- POST /mi
514-
- GET /mi
515514

516515
**What this test proves:**
517516
That you can submit MI data in the correct format and confirm it's recorded correctly.
518517

519518
| Criteria | Description |
520519
|---|---|
521-
| **Steps** | - Submit MI for a known number of processed letters. The MI should be grouped by specification and group ID<br>- Retrieve the same data with GET /mi<br>- Reconcile counts and timestamps with your local records. |
520+
| **Steps** | - Submit MI for a known number of processed letters. The MI should be grouped by specification and group ID<br>- Reconcile counts and timestamps with your local records. |
522521
| **Acceptance** | - MI entries appear in NHS Notify within expected timeframe<br>- Counts match processed letters <br>- No duplicates MI entries for the same date or missing records. |
523522
| **Evidence** | MI payloads and responses. |
524523
| **Business value** | Shows that operational and billing data are aligned and complete. |

infrastructure/terraform/components/api/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ No requirements.
3232

3333
| Name | Source | Version |
3434
|------|--------|---------|
35-
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
35+
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
3636
| <a name="module_domain_truststore"></a> [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
37-
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
37+
| <a name="module_get_letter_data"></a> [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
38+
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
3839
| <a name="module_kms"></a> [kms](#module\_kms) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-kms.zip | n/a |
3940
| <a name="module_logging_bucket"></a> [logging\_bucket](#module\_logging\_bucket) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
40-
| <a name="module_patch_letter"></a> [patch\_letter](#module\_patch\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
41+
| <a name="module_patch_letter"></a> [patch\_letter](#module\_patch\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4142
| <a name="module_s3bucket_test_letters"></a> [s3bucket\_test\_letters](#module\_s3bucket\_test\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
4243
| <a name="module_supplier_ssl"></a> [supplier\_ssl](#module\_supplier\_ssl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-ssl.zip | n/a |
4344
## Outputs

infrastructure/terraform/components/api/iam_role_api_gateway_execution_role.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
5050
resources = [
5151
module.authorizer_lambda.function_arn,
5252
module.get_letters.function_arn,
53-
module.patch_letter.function_arn
53+
module.patch_letter.function_arn,
54+
module.get_letter_data.function_arn
5455
]
5556
}
5657
}

infrastructure/terraform/components/api/locals.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ locals {
99
AWS_REGION = var.region
1010
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
1111
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
12+
GET_LETTER_DATA_LAMBDA_ARN = module.get_letter_data.function_arn
1213
PATCH_LETTER_LAMBDA_ARN = module.patch_letter.function_arn
1314
})
1415

1516
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"
1617

1718
common_lambda_env_vars = {
1819
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
19-
LETTER_TTL_HOURS = 24,
20-
SUPPLIER_ID_HEADER = "nhsd-supplier-id"
21-
APIM_CORRELATION_HEADER = "nhsd-correlation-id"
20+
LETTER_TTL_HOURS = 12960, # 18 months * 30 days * 24 hours
21+
SUPPLIER_ID_HEADER = "nhsd-supplier-id",
22+
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
23+
DOWNLOAD_URL_TTL_SECONDS = 60
2224
}
2325
}

infrastructure/terraform/components/api/module_authorizer_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "authorizer_lambda" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip"
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
33

44
aws_account_id = var.aws_account_id
55
component = var.component
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
module "get_letter_data" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
3+
4+
function_name = "get_letter_data"
5+
description = "Get the letter data"
6+
7+
aws_account_id = var.aws_account_id
8+
component = var.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.get_letter_data_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 = "api-handler/dist"
24+
function_include_common = true
25+
handler_function_name = "getLetterData"
26+
runtime = "nodejs22.x"
27+
memory = 128
28+
timeout = 5
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.destination_arn
36+
log_subscription_role_arn = local.acct.log_subscription_role_arn
37+
38+
lambda_env_vars = merge(local.common_lambda_env_vars, {})
39+
}
40+
41+
data "aws_iam_policy_document" "get_letter_data_lambda" {
42+
statement {
43+
sid = "KMSPermissions"
44+
effect = "Allow"
45+
46+
actions = [
47+
"kms:Decrypt",
48+
"kms:GenerateDataKey",
49+
]
50+
51+
resources = [
52+
module.kms.key_arn, ## Requires shared kms module
53+
]
54+
}
55+
56+
statement {
57+
sid = "AllowDynamoDBAccess"
58+
effect = "Allow"
59+
60+
actions = [
61+
"dynamodb:GetItem",
62+
"dynamodb:Query"
63+
]
64+
65+
resources = [
66+
aws_dynamodb_table.letters.arn,
67+
"${aws_dynamodb_table.letters.arn}/index/supplierStatus-index"
68+
]
69+
}
70+
71+
statement {
72+
sid = "S3GetObjectForPresign"
73+
actions = [
74+
"s3:GetObject",
75+
"s3:ListBucket"] # allows 404 response instead of 403 if object missing
76+
resources = ["${module.s3bucket_test_letters.arn}/*"]
77+
}
78+
}

infrastructure/terraform/components/api/module_lambda_get_letters.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "get_letters" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip"
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
33

44
function_name = "get_letters"
55
description = "Get paginated letter ids"

infrastructure/terraform/components/api/module_lambda_patch_letter.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "patch_letter" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip"
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
33

44
function_name = "patch_letter"
55
description = "Update the status of a letter"

infrastructure/terraform/components/api/resources/spec.tmpl.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,66 @@
105105
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${PATCH_LETTER_LAMBDA_ARN}/invocations"
106106
}
107107
}
108+
},
109+
"/letters/{id}/data": {
110+
"get": {
111+
"operationId": "getDataId",
112+
"responses": {
113+
"303": {
114+
"description": "See Other",
115+
"headers": {
116+
"Location": {
117+
"description": "The signed S3 URL of the data file to download",
118+
"example": "https://examples3bucket.com/filelocation",
119+
"schema": {
120+
"type": "string"
121+
}
122+
}
123+
}
124+
},
125+
"404": {
126+
"description": "Resource not found"
127+
},
128+
"429": {
129+
"description": "Too many requests"
130+
},
131+
"500": {
132+
"description": "Server error"
133+
}
134+
},
135+
"security": [
136+
{
137+
"LambdaAuthorizer": []
138+
}
139+
],
140+
"summary": "Fetch a data file",
141+
"x-amazon-apigateway-integration": {
142+
"contentHandling": "CONVERT_TO_TEXT",
143+
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
144+
"httpMethod": "POST",
145+
"passthroughBehavior": "WHEN_NO_TEMPLATES",
146+
"responses": {
147+
".*": {
148+
"statusCode": "200"
149+
}
150+
},
151+
"timeoutInMillis": 29000,
152+
"type": "AWS_PROXY",
153+
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${GET_LETTER_DATA_LAMBDA_ARN}/invocations"
154+
}
155+
},
156+
"parameters": [
157+
{
158+
"description": "Unique identifier of this resource",
159+
"in": "path",
160+
"name": "id",
161+
"required": true,
162+
"schema": {
163+
"example": "24L5eYSWGzCHlGmzNxuqVusPxDg",
164+
"type": "string"
165+
}
166+
}
167+
]
108168
}
109169
}
110170
}

0 commit comments

Comments
 (0)