Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module "authorizer_lambda" {
CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS = 30,
APIM_SUPPLIER_ID_HEADER = "NHSD-Supplier-ID",
SUPPLIERS_TABLE_NAME = aws_dynamodb_table.suppliers.name
LOG_REFERENCE = AUTHORIZER
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "amendment_event_transformer" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = AMENDMENT_EVENT_TRANSFORMER
})
}

data "aws_iam_policy_document" "amendment_event_transformer" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "get_letter" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = GET_LETTER
})
}

data "aws_iam_policy_document" "get_letter_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "get_letter_data" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = GET_LETTER_DATA
})
}

data "aws_iam_policy_document" "get_letter_data_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module "get_letters" {
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = merge(local.common_lambda_env_vars, {
MAX_LIMIT = var.max_get_limit
MAX_LIMIT = var.max_get_limit
LOG_REFERENCE = GET_LETTERS
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module "get_mi" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = GET_MI })
}

data "aws_iam_policy_document" "get_mi_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "get_status" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = GET_STATUS
})
}

data "aws_iam_policy_document" "get_status_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module "letter_updates_transformer" {
lambda_env_vars = merge(local.common_lambda_env_vars, {
EVENTPUB_SNS_TOPIC_ARN = "${module.eventpub.sns_topic.arn}",
EVENT_SOURCE = var.letter_event_source
LOG_REFERENCE = LETTER_UPDATES_TRANSFORMER
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module "mi_updates_transformer" {

lambda_env_vars = merge(local.common_lambda_env_vars, {
EVENTPUB_SNS_TOPIC_ARN = "${module.eventpub.sns_topic.arn}"
LOG_REFERENCE = MI_UPDATES_TRANSFORMER
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ module "patch_letter" {
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = merge(local.common_lambda_env_vars, {
QUEUE_URL = module.amendments_queue.sqs_queue_url
QUEUE_URL = module.amendments_queue.sqs_queue_url
LOG_REFERENCE = PATCH_LETTERS
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ module "post_letters" {
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = merge(local.common_lambda_env_vars, {
QUEUE_URL = module.amendments_queue.sqs_queue_url,
MAX_LIMIT = var.max_get_limit
QUEUE_URL = module.amendments_queue.sqs_queue_url,
MAX_LIMIT = var.max_get_limit
LOG_REFERENCE = POST_LETTERS
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "post_mi" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = POST_MI
})
}

data "aws_iam_policy_document" "post_mi_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module "supplier_allocator" {
lambda_env_vars = merge(local.common_lambda_env_vars, {
UPSERT_LETTERS_QUEUE_URL = module.sqs_letter_updates.sqs_queue_url,
IDEMPOTENCY_TABLE_NAME = aws_dynamodb_table.idempotency.name
LOG_REFERENCE = SUPPLIER_ALLOCATOR
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "supplier_config_ingress" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = SUPPLIER_CONFIG_INGRESS
})
}

data "aws_iam_policy_document" "supplier_config_ingress_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module "supplier_mock" {
GET_LETTERS_FUNCTION_NAME = module.get_letters.function_name
PATCH_LETTER_FUNCTION_NAME = module.patch_letter.function_name
SUPPLIER_MOCK_CONFIG_PARAM_NAME = aws_ssm_parameter.supplier_mock_config[0].name
LOG_REFERENCE = SUPPLIER_MOCK
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module "update_letter_queue" {
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, {})
lambda_env_vars = merge(local.common_lambda_env_vars, {
LOG_REFERENCE = UPDATE_LETTER
})
}

data "aws_iam_policy_document" "update_letter_queue_lambda" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module "upsert_letter" {

lambda_env_vars = merge(local.common_lambda_env_vars, {
IDEMPOTENCY_TABLE_NAME = aws_dynamodb_table.idempotency.name
LOG_REFERENCE = UPSERT_LETTER
})
}

Expand Down
7 changes: 6 additions & 1 deletion internal/helpers/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ import pino, { Logger } from "pino";

export type LoggerOptions = {
logLevel?: string;
logReference?: string;
};

/**
* Creates a configured pino logger instance for use across lambdas.
*
* @param options - Optional configuration for the logger
* @param options.logLevel - The log level (defaults to "info")
* @param options.logReference - Optional reference value to include on every log record
* @returns A configured pino Logger instance
*/
export function createLogger(options: LoggerOptions = {}): Logger {
const { logLevel = "info" } = options;
const { logLevel = "info", logReference } = options;

return pino({
level: logLevel,
mixin: () => {
return logReference ? { log_reference: logReference } : {};
},
formatters: {
level: (label) => {
return { level: label.toUpperCase() };
Expand Down
5 changes: 4 additions & 1 deletion lambdas/api-handler/src/config/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ function createMIRepository(log: Logger, environment: EnvVars): MIRepository {
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
s3Client: new S3Client(),
Expand Down
1 change: 1 addition & 0 deletions lambdas/api-handler/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const EnvVarsSchema = z.object({
PINO_LOG_LEVEL: z.coerce.string().optional(),
EVENT_SOURCE: z.string(),
SNS_TOPIC_ARN: z.string(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/authorizer/src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ function createSupplierRepository(
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
supplierRepo: createSupplierRepository(
Expand Down
1 change: 1 addition & 0 deletions lambdas/authorizer/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const EnvVarsSchema = z.object({
APIM_SUPPLIER_ID_HEADER: z.string(),
CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS: z.coerce.number().int(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/letter-updates-transformer/src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function createSNSClient(): SNSClient {
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
snsClient: createSNSClient(),
Expand Down
1 change: 1 addition & 0 deletions lambdas/letter-updates-transformer/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const EnvVarsSchema = z.object({
EVENTPUB_SNS_TOPIC_ARN: z.string(),
EVENT_SOURCE: z.string(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/mi-updates-transformer/src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function createSNSClient(): SNSClient {
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
snsClient: createSNSClient(),
Expand Down
1 change: 1 addition & 0 deletions lambdas/mi-updates-transformer/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";
const EnvVarsSchema = z.object({
EVENTPUB_SNS_TOPIC_ARN: z.string(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/supplier-allocator/src/config/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ function createIdempotencyLayer(): DynamoDBPersistenceLayer {
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
supplierConfigRepo: createSupplierConfigRepository(),
Expand Down
1 change: 1 addition & 0 deletions lambdas/supplier-allocator/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EnvVarsSchema = z.object({
SUPPLIER_QUOTAS_TABLE_NAME: z.string(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
IDEMPOTENCY_TABLE_NAME: z.string(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/supplier-config-ingress/src/config/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ function createSupplierConfigRepository(
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
supplierConfigRepo: createSupplierConfigRepository(envVars),
Expand Down
2 changes: 2 additions & 0 deletions lambdas/supplier-config-ingress/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { z } from "zod";
const EnvVarsSchema = z.object({
SUPPLIER_CONFIG_TABLE_NAME: z.string(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
IDEMPOTENCY_TABLE_NAME: z.string(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
6 changes: 5 additions & 1 deletion lambdas/supplier-mock/src/handler/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export type Deps = {
};

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

const lambdaClient = new LambdaClient();
const parameterStoreConfig = getParameterStoreConfig();

Expand Down
1 change: 1 addition & 0 deletions lambdas/supplier-mock/src/handler/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const EnvVarsSchema = z.object({
GET_LETTERS_FUNCTION_NAME: z.string().optional(),
PATCH_LETTER_FUNCTION_NAME: z.string().optional(),
SUPPLIER_MOCK_CONFIG_PARAM_NAME: z.string().optional(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/update-letter-queue/src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ function createDynamoDBDocumentClient(): DynamoDBDocumentClient {
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});
const ddbClient = createDynamoDBDocumentClient();

const letterQueueRepository = new LetterQueueRepository(ddbClient, log, {
Expand Down
1 change: 1 addition & 0 deletions lambdas/update-letter-queue/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const EnvVarsSchema = z.object({
LETTER_QUEUE_TABLE_NAME: z.string(),
LETTER_QUEUE_TTL_HOURS: z.coerce.number().int(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
5 changes: 4 additions & 1 deletion lambdas/upsert-letter/src/config/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function createIdempotencyLayer(): DynamoDBPersistenceLayer {
}

export function createDependenciesContainer(): Deps {
const log = createLogger({ logLevel: envVars.PINO_LOG_LEVEL });
const log = createLogger({
logLevel: envVars.PINO_LOG_LEVEL,
logReference: envVars.LOG_REFERENCE,
});

return {
letterRepo: createLetterRepository(log),
Expand Down
1 change: 1 addition & 0 deletions lambdas/upsert-letter/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EnvVarsSchema = z.object({
LETTER_TTL_HOURS: z.coerce.number().int(),
PINO_LOG_LEVEL: z.coerce.string().optional(),
IDEMPOTENCY_TABLE_NAME: z.string(),
LOG_REFERENCE: z.string().optional(),
});

export type EnvVars = z.infer<typeof EnvVarsSchema>;
Expand Down
Loading