-
Notifications
You must be signed in to change notification settings - Fork 5
CCM-17343: Add routing of supplier config events to no-op lambda #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| resource "aws_lambda_event_source_mapping" "supplier_config_ingress" { | ||
| event_source_arn = module.sqs_supplier_config.sqs_queue_arn | ||
| function_name = module.supplier_config_ingress.function_name | ||
| batch_size = 10 | ||
| maximum_batching_window_in_seconds = 5 | ||
| function_response_types = [ | ||
| "ReportBatchItemFailures" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| module "supplier_config_ingress" { | ||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip" | ||
|
|
||
| function_name = "supplier-config-ingress" | ||
| description = "Persist supplier config changes" | ||
|
|
||
| aws_account_id = var.aws_account_id | ||
| component = var.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.supplier_config_ingress_lambda.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 = "supplier-config-ingress/dist" | ||
| function_include_common = true | ||
| handler_function_name = "supplierConfigHandler" | ||
| runtime = "nodejs22.x" | ||
| memory = 512 | ||
| timeout = 29 | ||
| log_level = var.log_level | ||
|
|
||
| force_lambda_code_deploy = var.force_lambda_code_deploy | ||
| enable_lambda_insights = false | ||
|
|
||
| log_destination_arn = local.destination_arn | ||
| log_subscription_role_arn = local.acct.log_subscription_role_arn | ||
|
|
||
| lambda_env_vars = merge(local.common_lambda_env_vars, {}) | ||
| } | ||
|
stevebux marked this conversation as resolved.
|
||
|
|
||
| data "aws_iam_policy_document" "supplier_config_ingress_lambda" { | ||
| statement { | ||
| sid = "KMSPermissions" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "kms:Decrypt", | ||
| "kms:GenerateDataKey", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.kms.key_arn, | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "AllowSQSRead" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "sqs:ReceiveMessage", | ||
| "sqs:DeleteMessage", | ||
| "sqs:GetQueueAttributes" | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.sqs_supplier_config.sqs_queue_arn | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||
| module "sqs_supplier_config" { | ||||||||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| aws_account_id = var.aws_account_id | ||||||||
| component = var.component | ||||||||
| environment = var.environment | ||||||||
| project = var.project | ||||||||
| region = var.region | ||||||||
| name = "supplier-config" | ||||||||
|
|
||||||||
| sqs_kms_key_arn = module.kms.key_arn | ||||||||
|
|
||||||||
| visibility_timeout_seconds = 60 | ||||||||
|
|
||||||||
| create_dlq = true | ||||||||
| sqs_policy_overload = data.aws_iam_policy_document.supplier_config_queue_policy.json | ||||||||
| } | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This turns off the built-in alarm from the shared module - we have our own alarm for this |
||||||||
|
|
||||||||
| data "aws_iam_policy_document" "supplier_config_queue_policy" { | ||||||||
| version = "2012-10-17" | ||||||||
|
|
||||||||
| statement { | ||||||||
| sid = "AllowSNSPermissions" | ||||||||
| effect = "Allow" | ||||||||
|
|
||||||||
| principals { | ||||||||
| type = "Service" | ||||||||
| identifiers = ["sns.amazonaws.com"] | ||||||||
| } | ||||||||
|
|
||||||||
| actions = [ | ||||||||
| "sqs:SendMessage", | ||||||||
| "sqs:ListQueueTags", | ||||||||
| "sqs:GetQueueUrl", | ||||||||
| "sqs:GetQueueAttributes", | ||||||||
| ] | ||||||||
|
|
||||||||
| resources = [ | ||||||||
| "arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${var.component}-supplier-config-queue" | ||||||||
| ] | ||||||||
|
|
||||||||
| condition { | ||||||||
| test = "ArnEquals" | ||||||||
| variable = "aws:SourceArn" | ||||||||
| values = [module.eventsub.sns_topic.arn] | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| resource "aws_sns_topic_subscription" "eventsub_sqs_supplier_config" { | ||
| topic_arn = module.eventsub.sns_topic.arn | ||
| protocol = "sqs" | ||
| endpoint = module.sqs_supplier_config.sqs_queue_arn | ||
| raw_message_delivery = true | ||
|
|
||
| filter_policy_scope = "MessageBody" | ||
| filter_policy = jsonencode({ | ||
| type = [{ prefix = "uk.nhs.notify.supplier-config" }] | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| coverage | ||
| node_modules | ||
| dist | ||
| .reports |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| const baseJestConfig = { | ||
| preset: "ts-jest", | ||
| extensionsToTreatAsEsm: [".ts"], | ||
| transform: { | ||
| "^.+\\.ts$": [ | ||
| "ts-jest", | ||
| { | ||
| useESM: true, | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| // Automatically clear mock calls, instances, contexts and results before every test | ||
| clearMocks: true, | ||
|
|
||
| // Indicates whether the coverage information should be collected while executing the test | ||
| collectCoverage: true, | ||
|
|
||
| // The directory where Jest should output its coverage files | ||
| coverageDirectory: "./.reports/unit/coverage", | ||
|
|
||
| // Indicates which provider should be used to instrument code for coverage | ||
| coverageProvider: "babel", | ||
|
|
||
| coverageThreshold: { | ||
| global: { | ||
| branches: 100, | ||
| functions: 100, | ||
| lines: 100, | ||
| statements: -10, | ||
| }, | ||
| }, | ||
|
|
||
| coveragePathIgnorePatterns: ["/__tests__/"], | ||
| testPathIgnorePatterns: [".build"], | ||
| testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"], | ||
|
|
||
| // Use this configuration option to add custom reporters to Jest | ||
| reporters: [ | ||
| "default", | ||
| [ | ||
| "jest-html-reporter", | ||
| { | ||
| pageTitle: "Test Report", | ||
| outputPath: "./.reports/unit/test-report.html", | ||
| includeFailureMsg: true, | ||
| }, | ||
| ], | ||
| ], | ||
|
|
||
| // The test environment that will be used for testing | ||
| testEnvironment: "node", | ||
| }; | ||
|
|
||
| export default baseJestConfig; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "dependencies": { | ||
| "@types/aws-lambda": "^8.10.148", | ||
| "esbuild": "^0.27.2" | ||
| }, | ||
| "name": "nhs-notify-supplier-api-supplier-config-ingress", | ||
| "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" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { SQSEvent } from "aws-lambda"; | ||
| import { supplierConfigHandler } from ".."; | ||
|
|
||
| describe("supplierConfigHandler", () => { | ||
| it("returns an empty batchItemFailures list", async () => { | ||
| const event = { Records: [] } as unknown as SQSEvent; | ||
|
|
||
| const result = await supplierConfigHandler(event); | ||
|
|
||
| expect(result).toEqual({ batchItemFailures: [] }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { SQSBatchResponse, SQSEvent } from "aws-lambda"; | ||
|
|
||
| // eslint-disable-next-line import-x/prefer-default-export | ||
| export const supplierConfigHandler = async ( | ||
| _event: SQSEvent, | ||
| ): Promise<SQSBatchResponse> => { | ||
| // Implementation to be done under CCM-17379 | ||
| return { batchItemFailures: [] }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "types": [ | ||
| "jest", | ||
| "node" | ||
| ] | ||
| }, | ||
| "extends": "../../tsconfig.base.json", | ||
| "include": [ | ||
| "src/**/*", | ||
| "jest.config.ts" | ||
| ] | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty lines