Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions infrastructure/terraform/components/dl/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ locals {
ssm_senders_prefix = "${local.ssm_prefix}/senders"
ttl_shard_count = 3
unscanned_files_bucket = local.acct.additional_s3_buckets["digital-letters_unscanned-files"]["id"]
metrics_namespace_name = "nhs-${var.environment}-${var.component}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module "core_notifier" {
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"NHS_APP_BASE_URL" = var.nhs_app_base_url
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module "file_scanner" {
"UNSCANNED_FILES_PATH_PREFIX" = local.csi
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module "mesh_acknowledge" {
SSM_MESH_PREFIX = local.ssm_mesh_prefix
SSM_SENDERS_PREFIX = local.ssm_senders_prefix
USE_MESH_MOCK = var.enable_mock_mesh ? "true" : "false"
DL_METRICS_NAMESPACE = local.metrics_namespace_name
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module "mesh_download" {
SSM_MESH_PREFIX = local.ssm_mesh_prefix
SSM_SENDERS_PREFIX = local.ssm_senders_prefix
USE_MESH_MOCK = var.enable_mock_mesh ? "true" : "false"
DL_METRICS_NAMESPACE = local.metrics_namespace_name
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module "mesh_poll" {
SSM_MESH_PREFIX = local.ssm_mesh_prefix
SSM_SENDERS_PREFIX = local.ssm_senders_prefix
USE_MESH_MOCK = var.enable_mock_mesh ? "true" : "false"
DL_METRICS_NAMESPACE = local.metrics_namespace_name
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module "move_scanned_files" {
"UNSCANNED_FILE_S3_BUCKET_NAME" = local.unscanned_files_bucket
"SAFE_FILE_S3_BUCKET_NAME" = module.s3bucket_file_safe.bucket
"QUARANTINE_FILE_S3_BUCKET_NAME" = module.s3bucket_file_quarantine.bucket
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module "nhsapp_status_handler" {
"TTL_TABLE_NAME" = aws_dynamodb_table.ttl.name
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module "pdm_poll" {
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"POLL_MAX_RETRIES" = 10
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module "pdm_uploader" {
"APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.pdm_access_token_ssm_parameter_name
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module "print_analyser" {
lambda_env_vars = {
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module "print_sender" {
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"ACCOUNT_TYPE" = var.aws_account_type
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module "print_status_handler" {
lambda_env_vars = {
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ module "report_event_transformer" {

log_destination_arn = local.log_destination_arn
log_subscription_role_arn = local.acct.log_subscription_role_arn
lambda_env_vars = {
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module "report_generator" {
"REPORTING_BUCKET" = module.s3bucket_reporting.bucket
"REPORT_NAME" = "completed_communications"
"WAIT_FOR_IN_SECONDS" = var.athena_query_polling_time_seconds
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module "report_scheduler" {
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module "report_sender" {
SSM_MESH_PREFIX = local.ssm_mesh_prefix
SSM_SENDERS_PREFIX = local.ssm_senders_prefix
USE_MESH_MOCK = var.enable_mock_mesh ? "true" : "false"
DL_METRICS_NAMESPACE = local.metrics_namespace_name
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module "ttl_create" {
"TTL_SHARD_COUNT" = local.ttl_shard_count
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module "ttl_handle_expiry" {
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
"DLQ_URL" = module.sqs_ttl_handle_expiry_errors.sqs_queue_url
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ module "ttl_poll" {
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = {
"TTL_TABLE_NAME" = aws_dynamodb_table.ttl.name
"CONCURRENCY" = 60
"MAX_PROCESS_SECONDS" = 300
"TTL_SHARD_COUNT" = local.ttl_shard_count
"TTL_TABLE_NAME" = aws_dynamodb_table.ttl.name
"CONCURRENCY" = 60
"MAX_PROCESS_SECONDS" = 300
"TTL_SHARD_COUNT" = local.ttl_shard_count
"ENVIRONMENT" = var.environment
"DL_METRICS_NAMESPACE" = local.metrics_namespace_name
}
}

Expand Down
24 changes: 24 additions & 0 deletions lambdas/core-notifier-lambda/src/__tests__/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,31 @@ jest.mock('utils', () => ({
debug: jest.fn(),
},
EventPublisher: jest.fn(),
MetricHandler: jest.fn(),
eventBridgeClient: {},
sqsClient: {},
DimensionName: {
Component: 'Component',
Flow: 'Flow',
Environment: 'Environment',
SenderId: 'SenderId',
LambdaFunction: 'LambdaFunction',
},
FlowDimension: {
DigitalLetter: 'Digital Letter',
Print: 'Print',
TrustReporting: 'Trust Reporting',
},
ComponentDimension: {
MESH: 'MESH',
PDM: 'PDM',
TTL: 'TTL',
CoreNotify: 'Core Notify',
VirusScanning: 'Virus Scanning',
PrintRequest: 'Print Request',
Reporting: 'Reporting',
Callbacks: 'Callbacks',
},
}));

jest.mock('app/notify-api-client');
Expand All @@ -42,6 +65,7 @@ describe('createContainer', () => {
apimBaseUrl: 'https://api.test.nhs.uk',
environment: 'test',
nhsAppBaseUrl: 'https://example.com',
dlMetricsNamespace: 'test-namespace',
};

const mockSenderManagement = mock<ISenderManagement>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('loadConfig', () => {
apimBaseUrl: 'https://api.test.nhs.uk',
nhsAppBaseUrl: 'https://example.com',
environment: 'test',
dlMetricsNamespace: 'test-namespace',
};

mockGetValue
Expand All @@ -32,12 +33,13 @@ describe('loadConfig', () => {
.mockReturnValueOnce(mockConfig.apimAccessTokenSsmParameterName)
.mockReturnValueOnce(mockConfig.apimBaseUrl)
.mockReturnValueOnce(mockConfig.nhsAppBaseUrl)
.mockReturnValueOnce(mockConfig.environment);
.mockReturnValueOnce(mockConfig.environment)
.mockReturnValueOnce(mockConfig.dlMetricsNamespace);

const result = loadConfig();

expect(result).toEqual(mockConfig);
expect(mockGetValue).toHaveBeenCalledTimes(6);
expect(mockGetValue).toHaveBeenCalledTimes(7);
expect(mockGetValue).toHaveBeenNthCalledWith(
1,
'EVENT_PUBLISHER_EVENT_BUS_ARN',
Expand All @@ -50,6 +52,7 @@ describe('loadConfig', () => {
expect(mockGetValue).toHaveBeenNthCalledWith(4, 'APIM_BASE_URL');
expect(mockGetValue).toHaveBeenNthCalledWith(5, 'NHS_APP_BASE_URL');
expect(mockGetValue).toHaveBeenNthCalledWith(6, 'ENVIRONMENT');
expect(mockGetValue).toHaveBeenNthCalledWith(7, 'DL_METRICS_NAMESPACE');
});

it('returns config with correct types', () => {
Expand All @@ -59,7 +62,8 @@ describe('loadConfig', () => {
.mockReturnValueOnce('/param')
.mockReturnValueOnce('https://api')
.mockReturnValueOnce('https://example.com')
.mockReturnValueOnce('prod');
.mockReturnValueOnce('prod')
.mockReturnValueOnce('test-namespace');

const result: NotifySendMessageConfig = loadConfig();

Expand All @@ -69,5 +73,6 @@ describe('loadConfig', () => {
expect(typeof result.apimBaseUrl).toBe('string');
expect(typeof result.nhsAppBaseUrl).toBe('string');
expect(typeof result.environment).toBe('string');
expect(typeof result.dlMetricsNamespace).toBe('string');
});
});
17 changes: 16 additions & 1 deletion lambdas/core-notifier-lambda/src/container.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {
ComponentDimension,
DimensionName,
EventPublisher,
FlowDimension,
MetricHandler,
ParameterStoreCache,
createGetApimAccessToken,
eventBridgeClient,
Expand Down Expand Up @@ -41,14 +45,25 @@ export async function createContainer(): Promise<SqsHandlerDependencies> {
logger,
});

const { eventPublisherDlqUrl, eventPublisherEventBusArn } = config;
const {
dlMetricsNamespace,
eventPublisherDlqUrl,
eventPublisherEventBusArn,
} = config;
const metricHandler = new MetricHandler(dlMetricsNamespace, [
{ Name: DimensionName.Environment, Value: config.environment },
{ Name: DimensionName.Flow, Value: FlowDimension.DigitalLetter },
{ Name: DimensionName.Component, Value: ComponentDimension.CoreNotify },
{ Name: DimensionName.LambdaFunction, Value: 'core-notifier' },
]);

const eventPublisher = new EventPublisher({
eventBusArn: eventPublisherEventBusArn,
dlqUrl: eventPublisherDlqUrl,
logger,
sqsClient,
eventBridgeClient,
metricHandler,
});

const coreRequestMapper = new CoreRequestMapper(config.nhsAppBaseUrl);
Expand Down
2 changes: 2 additions & 0 deletions lambdas/core-notifier-lambda/src/infra/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type NotifySendMessageConfig = {
apimBaseUrl: string;
nhsAppBaseUrl: string;
environment: string;
dlMetricsNamespace: string;
};

export function loadConfig(): NotifySendMessageConfig {
Expand All @@ -23,5 +24,6 @@ export function loadConfig(): NotifySendMessageConfig {
apimBaseUrl: defaultConfigReader.getValue('APIM_BASE_URL'),
nhsAppBaseUrl: defaultConfigReader.getValue('NHS_APP_BASE_URL'),
environment: defaultConfigReader.getValue('ENVIRONMENT'),
dlMetricsNamespace: defaultConfigReader.getValue('DL_METRICS_NAMESPACE'),
};
}
4 changes: 4 additions & 0 deletions lambdas/file-scanner-lambda/src/__tests__/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ describe('createContainer', () => {
it('should create container with all dependencies', () => {
mockLoadConfig.mockReturnValue({
documentReferenceBucket: 'test-doc-ref-bucket',
environment: 'test',
unscannedFilesBucket: 'test-unscanned-bucket',
unscannedFilesPathPrefix: 'dev',
eventPublisherEventBusArn:
'arn:aws:events:us-east-1:123456789012:event-bus/test',
eventPublisherDlqUrl: 'https://sqs.us-east-1.amazonaws.com/dlq',
dlMetricsNamespace: 'test-namespace',
});

const container = createContainer();
Expand All @@ -33,10 +35,12 @@ describe('createContainer', () => {
it('should call loadConfig to get configuration', () => {
const mockConfig = {
documentReferenceBucket: 'test-bucket',
environment: 'test',
unscannedFilesBucket: 'test-unscanned',
unscannedFilesPathPrefix: 'dev',
eventPublisherEventBusArn: 'arn:test',
eventPublisherDlqUrl: 'url:test',
dlMetricsNamespace: 'test-namespace',
};

mockLoadConfig.mockReturnValue(mockConfig);
Expand Down
4 changes: 4 additions & 0 deletions lambdas/file-scanner-lambda/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// Set environment variables before any imports
process.env.DOCUMENT_REFERENCE_BUCKET = 'test-doc-ref-bucket';
process.env.ENVIRONMENT = 'test';
process.env.UNSCANNED_FILES_BUCKET = 'test-unscanned-bucket';
process.env.UNSCANNED_FILES_PATH_PREFIX = 'test-prefix';
process.env.EVENT_PUBLISHER_EVENT_BUS_ARN =
'arn:aws:events:us-east-1:123456789012:event-bus/test-bus';
process.env.EVENT_PUBLISHER_DLQ_URL =
'https://sqs.us-east-1.amazonaws.com/123456789012/test-dlq';
process.env.DL_METRICS_NAMESPACE = 'test-namespace';

// eslint-disable-next-line import-x/first
import { handler } from '..';

describe('Lambda Handler', () => {
afterAll(() => {
delete process.env.DOCUMENT_REFERENCE_BUCKET;
delete process.env.ENVIRONMENT;
delete process.env.UNSCANNED_FILES_BUCKET;
delete process.env.UNSCANNED_FILES_PATH_PREFIX;
delete process.env.EVENT_PUBLISHER_EVENT_BUS_ARN;
delete process.env.EVENT_PUBLISHER_DLQ_URL;
delete process.env.DL_METRICS_NAMESPACE;
});

it('should export handler function', () => {
Expand Down
Loading
Loading