Skip to content

Commit 867a096

Browse files
CCM-12613: Upload to PDM component (#137)
1 parent 2cc7618 commit 867a096

Some content is hidden

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

47 files changed

+1984
-58
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 |
@@ -40,10 +40,12 @@ No requirements.
4040
| <a name="module_lambda_apim_key_generation"></a> [lambda\_apim\_key\_generation](#module\_lambda\_apim\_key\_generation) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4141
| <a name="module_lambda_lambda_apim_refresh_token"></a> [lambda\_lambda\_apim\_refresh\_token](#module\_lambda\_lambda\_apim\_refresh\_token) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4242
| <a name="module_mesh_poll"></a> [mesh\_poll](#module\_mesh\_poll) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
43+
| <a name="module_pdm_uploader"></a> [pdm\_uploader](#module\_pdm\_uploader) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4344
| <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 |
4445
| <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 |
4546
| <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 |
4647
| <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_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 |
4749
| <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 |
4850
| <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 |
4951
| <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 |

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
@@ -12,9 +12,16 @@ resource "aws_cloudwatch_event_rule" "mesh_inbox_message_downloaded" {
1212
})
1313
}
1414

15-
resource "aws_cloudwatch_event_target" "mesh_inbox_message_downloaded" {
15+
resource "aws_cloudwatch_event_target" "create-ttl-target" {
1616
rule = aws_cloudwatch_event_rule.mesh_inbox_message_downloaded.name
1717
arn = module.sqs_ttl.sqs_queue_arn
18-
target_id = "mesh-inbox-message-downloaded-target"
18+
target_id = "create-ttl-target"
19+
event_bus_name = aws_cloudwatch_event_bus.main.name
20+
}
21+
22+
resource "aws_cloudwatch_event_target" "pdm-uploader-target" {
23+
rule = aws_cloudwatch_event_rule.mesh_inbox_message_downloaded.name
24+
arn = module.sqs_pdm_uploader.sqs_queue_arn
25+
target_id = "pdm-uploader-target"
1926
event_bus_name = aws_cloudwatch_event_bus.main.name
2027
}
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_pdm_uploader_lambda" {
2+
event_source_arn = module.sqs_pdm_uploader.sqs_queue_arn
3+
function_name = module.pdm_uploader.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_apim_refresh_token.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ module "lambda_lambda_apim_refresh_token" {
3737
log_subscription_role_arn = local.acct.log_subscription_role_arn
3838

3939
lambda_env_vars = {
40-
NHS_AUTH_SERVER_TOKEN_ENDPOINT = var.apim_auth_token_url
41-
SSM_ACCESS_TOKEN_PARAMETER_NAME = local.apim_access_token_ssm_parameter_name
42-
SSM_API_KEY_PARAMETER_NAME = local.apim_api_key_ssm_parameter_name
43-
SSM_PRIVATE_KEY_PARAMETER_NAME = local.apim_private_key_ssm_parameter_name
44-
ENVIRONMENT = var.environment
40+
APIM_AUTH_TOKEN_URL = var.apim_auth_token_url
41+
APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME = local.apim_access_token_ssm_parameter_name
42+
APIM_API_KEY_SSM_PARAMETER_NAME = local.apim_api_key_ssm_parameter_name
43+
APIM_PRIVATE_KEY_SSM_PARAMETER_NAME = local.apim_private_key_ssm_parameter_name
44+
ENVIRONMENT = var.environment
4545
}
4646
}
4747

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
module "pdm_uploader" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
3+
4+
function_name = "pdm-uploader"
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.pdm_uploader_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 = "pdm-uploader-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" "pdm_uploader_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_pdm_uploader.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_pdm_uploader" {
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 = "pdm-uploader"
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_pdm_uploader.json
18+
}
19+
20+
data "aws_iam_policy_document" "sqs_pdm_uploader" {
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}-pdm-uploader-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" {

lambdas/mesh-poll/src/__tests__/index.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe('event-logging Lambda', () => {
3535
messageReference: 'incididunt Ut aute laborum',
3636
senderId: 'officia voluptate culpa Ut dolor',
3737
resourceId: 'a2bcbb42-ab7e-42b6-88d6-74f8d3ca4a09',
38-
retryCount: 97_903_257,
3938
},
4039
};
4140

lambdas/mesh-poll/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const handler: Handler = async (event: PDMResourceSubmitted) => {
3535
messageReference: 'incididunt Ut aute laborum',
3636
senderId: 'officia voluptate culpa Ut dolor',
3737
resourceId: 'a2bcbb42-ab7e-42b6-88d6-74f8d3ca4a09',
38-
retryCount: 97_903_257,
3938
},
4039
};
4140

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { baseJestConfig } from '../../jest.config.base';
2+
3+
const config = baseJestConfig;
4+
5+
export default config;

0 commit comments

Comments
 (0)