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
@@ -0,0 +1,59 @@
resource "aws_dynamodb_table" "supplier-configuration" {
name = "${local.csi}-supplier-config"
billing_mode = "PAY_PER_REQUEST"

hash_key = "PK"
range_key = "SK"

ttl {
attribute_name = "ttl"
enabled = true
}

attribute {
name = "PK"
type = "S"
}

attribute {
name = "SK"
type = "S"
}

attribute {
name = "entityType"
type = "S"
}

attribute {
name = "volumeGroup"
type = "S"
}

// The type-index GSI allows us to query for all supplier configurations of a given type (e.g. all letter supplier configurations)
global_secondary_index {
name = "EntityTypeIndex"
hash_key = "entityType"
range_key = "SK"
projection_type = "ALL"
}

global_secondary_index {
name = "volumeGroup-index"
hash_key = "PK"
range_key = "volumeGroup"
projection_type = "ALL"
}

point_in_time_recovery {
enabled = true
}

tags = merge(
local.default_tags,
{
NHSE-Enable-Dynamo-Backup-Acct = "True"
}
)

}
19 changes: 10 additions & 9 deletions infrastructure/terraform/components/api/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ locals {
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"

common_lambda_env_vars = {
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
MI_TABLE_NAME = aws_dynamodb_table.mi.name,
LETTER_TTL_HOURS = 12960, # 18 months * 30 days * 24 hours
MI_TTL_HOURS = 2160 # 90 days * 24 hours
SUPPLIER_ID_HEADER = "nhsd-supplier-id",
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
DOWNLOAD_URL_TTL_SECONDS = 60
SNS_TOPIC_ARN = "${module.eventsub.sns_topic.arn}",
EVENT_SOURCE = "/data-plane/supplier-api/${var.group}/${var.environment}/letters"
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
MI_TABLE_NAME = aws_dynamodb_table.mi.name,
LETTER_TTL_HOURS = 12960, # 18 months * 30 days * 24 hours
MI_TTL_HOURS = 2160 # 90 days * 24 hours
SUPPLIER_ID_HEADER = "nhsd-supplier-id",
APIM_CORRELATION_HEADER = "nhsd-correlation-id",
DOWNLOAD_URL_TTL_SECONDS = 60
SNS_TOPIC_ARN = "${module.eventsub.sns_topic.arn}",
EVENT_SOURCE = "/data-plane/supplier-api/${var.group}/${var.environment}/letters"
SUPPLIER_CONFIG_TABLE_NAME = aws_dynamodb_table.supplier-configuration.name
}

core_pdf_bucket_arn = "arn:aws:s3:::comms-${var.core_account_id}-eu-west-2-${var.core_environment}-api-stg-pdf-pipeline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,20 @@ data "aws_iam_policy_document" "supplier_allocator_lambda" {
module.sqs_letter_updates.sqs_queue_arn
]
}

statement {
sid = "AllowDynamoDBAccess"
effect = "Allow"

actions = [
"dynamodb:GetItem",
"dynamodb:Query"
]

resources = [
aws_dynamodb_table.supplier-configuration.arn,
"${aws_dynamodb_table.supplier-configuration.arn}/index/volumeGroup-index"

]
}
}
3 changes: 3 additions & 0 deletions internal/datastore/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const baseJestConfig: Config = {

coveragePathIgnorePatterns: ["/__tests__/"],
transform: { "^.+\\.ts$": "ts-jest" },
transformIgnorePatterns: [
"node_modules/(?!(@nhsdigital/nhs-notify-event-schemas-supplier-config)/)",
],
testPathIgnorePatterns: [".build"],
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],

Expand Down
1 change: 1 addition & 0 deletions internal/datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"@aws-sdk/client-dynamodb": "^3.984.0",
"@aws-sdk/lib-dynamodb": "^3.984.0",
"@internal/helpers": "*",
"@nhsdigital/nhs-notify-event-schemas-supplier-config": "^1.0.1",
"pino": "^10.3.0",
"zod": "^4.1.11",
"zod-mermaid": "^1.0.9"
Expand Down
28 changes: 28 additions & 0 deletions internal/datastore/src/__test__/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function setupDynamoDBContainer() {
lettersTtlHours: 1,
letterQueueTtlHours: 1,
miTtlHours: 1,
supplierConfigTableName: "supplier-config",
};

return {
Expand Down Expand Up @@ -145,6 +146,31 @@ const createLetterQueueTableCommand = new CreateTableCommand({
{ AttributeName: "queueTimestamp", AttributeType: "S" },
],
});
const createSupplierConfigTableCommand = new CreateTableCommand({
TableName: "supplier-config",
BillingMode: "PAY_PER_REQUEST",
KeySchema: [
{ AttributeName: "PK", KeyType: "HASH" }, // Partition key
{ AttributeName: "SK", KeyType: "RANGE" }, // Sort key
],
GlobalSecondaryIndexes: [
{
IndexName: "volumeGroup-index",
KeySchema: [
{ AttributeName: "PK", KeyType: "HASH" }, // Partition key for GSI
{ AttributeName: "volumeGroup", KeyType: "RANGE" }, // Sort key for GSI
],
Projection: {
ProjectionType: "ALL",
},
},
],
AttributeDefinitions: [
{ AttributeName: "PK", AttributeType: "S" },
{ AttributeName: "SK", AttributeType: "S" },
{ AttributeName: "volumeGroup", AttributeType: "S" },
],
});

export async function createTables(context: DBContext) {
const { ddbClient } = context;
Expand All @@ -155,6 +181,7 @@ export async function createTables(context: DBContext) {
await ddbClient.send(createMITableCommand);
await ddbClient.send(createSupplierTableCommand);
await ddbClient.send(createLetterQueueTableCommand);
await ddbClient.send(createSupplierConfigTableCommand);
}

export async function deleteTables(context: DBContext) {
Expand All @@ -165,6 +192,7 @@ export async function deleteTables(context: DBContext) {
"management-info",
"suppliers",
"letter-queue",
"supplier-config",
]) {
await ddbClient.send(
new DeleteTableCommand({
Expand Down
Loading
Loading