Skip to content

Commit 779f02a

Browse files
committed
CCM-17343: Add routing of supplier config events to no-op lambda
1 parent e88096e commit 779f02a

12 files changed

Lines changed: 269 additions & 0 deletions

infrastructure/terraform/components/api/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ No requirements.
7777
| <a name="module_sqs_alarms"></a> [sqs\_alarms](#module\_sqs\_alarms) | ../../modules/alarms-sqs | n/a |
7878
| <a name="module_sqs_letter_updates"></a> [sqs\_letter\_updates](#module\_sqs\_letter\_updates) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
7979
| <a name="module_sqs_supplier_allocator"></a> [sqs\_supplier\_allocator](#module\_sqs\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
80+
| <a name="module_sqs_supplier_config"></a> [sqs\_supplier\_config](#module\_sqs\_supplier\_config) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
8081
| <a name="module_supplier_allocator"></a> [supplier\_allocator](#module\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
82+
| <a name="module_supplier_config_ingress"></a> [supplier\_config\_ingress](#module\_supplier\_config\_ingress) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
8183
| <a name="module_supplier_ssl"></a> [supplier\_ssl](#module\_supplier\_ssl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-ssl.zip | n/a |
8284
| <a name="module_update_letter_queue"></a> [update\_letter\_queue](#module\_update\_letter\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
8385
| <a name="module_upsert_letter"></a> [upsert\_letter](#module\_upsert\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_lambda_event_source_mapping" "supplier_config_ingress" {
2+
event_source_arn = module.sqs_supplier_config.sqs_queue_arn
3+
function_name = module.supplier_config_ingress.function_name
4+
batch_size = 10
5+
maximum_batching_window_in_seconds = 5
6+
function_response_types = [
7+
"ReportBatchItemFailures"
8+
]
9+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
module "supplier_config_ingress" {
11+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip"
12+
13+
function_name = "supplier-config-ingress"
14+
description = "Persist supplier config changes"
15+
16+
aws_account_id = var.aws_account_id
17+
component = var.component
18+
environment = var.environment
19+
project = var.project
20+
region = var.region
21+
group = var.group
22+
23+
log_retention_in_days = var.log_retention_in_days
24+
kms_key_arn = module.kms.key_arn
25+
26+
iam_policy_document = {
27+
body = data.aws_iam_policy_document.supplier_config_ingress_lambda.json
28+
}
29+
30+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
31+
function_code_base_path = local.aws_lambda_functions_dir_path
32+
function_code_dir = "supplier-config-ingress/dist"
33+
function_include_common = true
34+
handler_function_name = "supplierConfigHandler"
35+
runtime = "nodejs22.x"
36+
memory = 512
37+
timeout = 29
38+
log_level = var.log_level
39+
40+
force_lambda_code_deploy = var.force_lambda_code_deploy
41+
enable_lambda_insights = false
42+
43+
log_destination_arn = local.destination_arn
44+
log_subscription_role_arn = local.acct.log_subscription_role_arn
45+
46+
lambda_env_vars = merge(local.common_lambda_env_vars, {})
47+
}
48+
49+
data "aws_iam_policy_document" "supplier_config_ingress_lambda" {
50+
statement {
51+
sid = "KMSPermissions"
52+
effect = "Allow"
53+
54+
actions = [
55+
"kms:Decrypt",
56+
"kms:GenerateDataKey",
57+
]
58+
59+
resources = [
60+
module.kms.key_arn,
61+
]
62+
}
63+
64+
statement {
65+
sid = "AllowSQSRead"
66+
effect = "Allow"
67+
68+
actions = [
69+
"sqs:ReceiveMessage",
70+
"sqs:DeleteMessage",
71+
"sqs:GetQueueAttributes"
72+
]
73+
74+
resources = [
75+
module.sqs_supplier_config.sqs_queue_arn
76+
]
77+
}
78+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module "sqs_supplier_config" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip"
3+
4+
aws_account_id = var.aws_account_id
5+
component = var.component
6+
environment = var.environment
7+
project = var.project
8+
region = var.region
9+
name = "supplier-config"
10+
11+
sqs_kms_key_arn = module.kms.key_arn
12+
13+
visibility_timeout_seconds = 60
14+
15+
create_dlq = true
16+
sqs_policy_overload = data.aws_iam_policy_document.supplier_config_queue_policy.json
17+
}
18+
19+
data "aws_iam_policy_document" "supplier_config_queue_policy" {
20+
version = "2012-10-17"
21+
22+
statement {
23+
sid = "AllowSNSPermissions"
24+
effect = "Allow"
25+
26+
principals {
27+
type = "Service"
28+
identifiers = ["sns.amazonaws.com"]
29+
}
30+
31+
actions = [
32+
"sqs:SendMessage",
33+
"sqs:ListQueueTags",
34+
"sqs:GetQueueUrl",
35+
"sqs:GetQueueAttributes",
36+
]
37+
38+
resources = [
39+
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${var.component}-supplier-config-queue"
40+
]
41+
42+
condition {
43+
test = "ArnEquals"
44+
variable = "aws:SourceArn"
45+
values = [module.eventsub.sns_topic.arn]
46+
}
47+
}
48+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "aws_sns_topic_subscription" "eventsub_sqs_supplier_config" {
2+
topic_arn = module.eventsub.sns_topic.arn
3+
protocol = "sqs"
4+
endpoint = module.sqs_supplier_config.sqs_queue_arn
5+
raw_message_delivery = true
6+
7+
filter_policy_scope = "MessageBody"
8+
filter_policy = jsonencode({
9+
type = [{ prefix = "uk.nhs.notify.supplier-config" }]
10+
})
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage
2+
node_modules
3+
dist
4+
.reports
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const baseJestConfig = {
2+
preset: "ts-jest",
3+
extensionsToTreatAsEsm: [".ts"],
4+
transform: {
5+
"^.+\\.ts$": [
6+
"ts-jest",
7+
{
8+
useESM: true,
9+
},
10+
],
11+
},
12+
13+
// Automatically clear mock calls, instances, contexts and results before every test
14+
clearMocks: true,
15+
16+
// Indicates whether the coverage information should be collected while executing the test
17+
collectCoverage: true,
18+
19+
// The directory where Jest should output its coverage files
20+
coverageDirectory: "./.reports/unit/coverage",
21+
22+
// Indicates which provider should be used to instrument code for coverage
23+
coverageProvider: "babel",
24+
25+
coverageThreshold: {
26+
global: {
27+
branches: 100,
28+
functions: 100,
29+
lines: 100,
30+
statements: -10,
31+
},
32+
},
33+
34+
coveragePathIgnorePatterns: ["/__tests__/"],
35+
testPathIgnorePatterns: [".build"],
36+
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],
37+
38+
// Use this configuration option to add custom reporters to Jest
39+
reporters: [
40+
"default",
41+
[
42+
"jest-html-reporter",
43+
{
44+
pageTitle: "Test Report",
45+
outputPath: "./.reports/unit/test-report.html",
46+
includeFailureMsg: true,
47+
},
48+
],
49+
],
50+
51+
// The test environment that will be used for testing
52+
testEnvironment: "node",
53+
};
54+
55+
export default baseJestConfig;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"dependencies": {
3+
"@types/aws-lambda": "^8.10.148",
4+
"esbuild": "^0.27.2"
5+
},
6+
"name": "nhs-notify-supplier-api-supplier-config-ingress",
7+
"private": true,
8+
"scripts": {
9+
"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",
10+
"lint": "eslint .",
11+
"lint:fix": "eslint . --fix",
12+
"test:unit": "jest",
13+
"typecheck": "tsc --noEmit"
14+
},
15+
"version": "0.0.1"
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { SQSEvent } from "aws-lambda";
2+
import { supplierConfigHandler } from "..";
3+
4+
describe("supplierConfigHandler", () => {
5+
it("returns an empty batchItemFailures list", async () => {
6+
const event = { Records: [] } as unknown as SQSEvent;
7+
8+
const result = await supplierConfigHandler(event);
9+
10+
expect(result).toEqual({ batchItemFailures: [] });
11+
});
12+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { SQSBatchResponse, SQSEvent } from "aws-lambda";
2+
3+
// eslint-disable-next-line import-x/prefer-default-export
4+
export const supplierConfigHandler = async (
5+
_event: SQSEvent,
6+
): Promise<SQSBatchResponse> => {
7+
// Implementation to be done under CCM-17379
8+
return { batchItemFailures: [] };
9+
};

0 commit comments

Comments
 (0)