From 64b15ba5f8e06a906691da487624a62378f35f43 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Wed, 27 Nov 2024 11:36:06 +0000 Subject: [PATCH 01/10] updates isReady attribute type --- packages/cdk/resources/Dynamodb.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cdk/resources/Dynamodb.ts b/packages/cdk/resources/Dynamodb.ts index 41edd44..65d0583 100644 --- a/packages/cdk/resources/Dynamodb.ts +++ b/packages/cdk/resources/Dynamodb.ts @@ -142,7 +142,7 @@ export class Dynamodb extends Construct { }, sortKey: { name: "isReady", - type: AttributeType.STRING + type: AttributeType.NUMBER }, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ From ac0beb9a429e9e1574d7307a2a292f2a0be44042 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Wed, 27 Nov 2024 11:40:31 +0000 Subject: [PATCH 02/10] removes magic string attribute names --- packages/cdk/resources/Dynamodb.ts | 85 +++++++++++++++++++----------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/packages/cdk/resources/Dynamodb.ts b/packages/cdk/resources/Dynamodb.ts index 65d0583..c53d757 100644 --- a/packages/cdk/resources/Dynamodb.ts +++ b/packages/cdk/resources/Dynamodb.ts @@ -16,6 +16,29 @@ import { import {Key} from "aws-cdk-lib/aws-kms" import {Duration, RemovalPolicy} from "aws-cdk-lib" +enum Attributes { + PRIMARY_KEY = "pk", + SORT_KEY = "sk", + NHS_NUMBER = "nhsNumber", + CREATION_DATETIME = "creationDatetime", + INDEXES = "indexes", + PRESCRIBER_ORG = "prescriberOrg", + DISPENSER_ORG = "dispenserOrg", + NOMINATED_PHARMACY = "nominatedPharmacy", + IS_READY = "isReady", + STATUS = "status", + CLAIM_IDS = "claimIds", + NEXT_ACTIVITY = "nextActivity", + NEXT_ACTIVITY_DATE = "nextActivityDate", + DOC_REF_TITLE = "docRefTitle", + STORE_TIME = "storeTime", + BACKSTOP_DELETE_DATE = "backstopDeleteDate", + PRESCRIPTION_ID = "prescriptionId", + SEQUENCE_NUMBER = "sequenceNumber", + SEQUENCE_NUMBER_NWSSP = "sequenceNumberNwssp", + EXPIRE_AT = "expireAt" +} + export interface DynamodbProps { readonly stackName: string readonly account: string @@ -67,11 +90,11 @@ export class Dynamodb extends Construct { // the table const DatastoreTable = new TableV2(this, "DatastoreTable", { partitionKey: { - name: "pk", + name: Attributes.PRIMARY_KEY, type: AttributeType.STRING }, sortKey: { - name: "sk", + name: Attributes.SORT_KEY, type: AttributeType.STRING }, tableName: `${props.stackName}-datastore`, @@ -79,98 +102,98 @@ export class Dynamodb extends Construct { pointInTimeRecovery: true, encryption: TableEncryptionV2.customerManagedKey(DatastoreKmsKey), billing: Billing.onDemand(), - timeToLiveAttribute: "expireAt" + timeToLiveAttribute: Attributes.EXPIRE_AT }) // global secondary indexes DatastoreTable.addGlobalSecondaryIndex({ indexName: "nhsNumberDate", partitionKey: { - name: "nhsNumber", + name: Attributes.NHS_NUMBER, type: AttributeType.STRING }, sortKey: { - name: "creationDatetime", + name: Attributes.CREATION_DATETIME, type: AttributeType.STRING }, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - "indexes", - "prescriberOrg", - "dispenserOrg" + Attributes.INDEXES, + Attributes.PRESCRIBER_ORG, + Attributes.DISPENSER_ORG ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "prescriberDate", partitionKey: { - name: "prescriberOrg", + name: Attributes.PRESCRIBER_ORG, type: AttributeType.STRING }, sortKey: { - name: "creationDatetime", + name: Attributes.CREATION_DATETIME, type: AttributeType.STRING }, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - "indexes", - "dispenserOrg" + Attributes.INDEXES, + Attributes.DISPENSER_ORG ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "dispenserDate", partitionKey: { - name: "dispenserOrg", + name: Attributes.DISPENSER_ORG, type: AttributeType.STRING }, sortKey: { - name: "creationDatetime", + name: Attributes.CREATION_DATETIME, type: AttributeType.STRING }, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - "indexes" + Attributes.INDEXES ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "nominatedPharmacyStatus", partitionKey: { - name: "nominatedPharmacy", + name: Attributes.NOMINATED_PHARMACY, type: AttributeType.STRING }, sortKey: { - name: "isReady", + name: Attributes.IS_READY, type: AttributeType.NUMBER }, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - "status", - "indexes" + Attributes.STATUS, + Attributes.INDEXES ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "claimId", partitionKey: { - name: "sk", + name: Attributes.SORT_KEY, type: AttributeType.STRING }, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - "claimIds" + Attributes.CLAIM_IDS ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "nextActivityDate", partitionKey: { - name: "nextActivity", + name: Attributes.NEXT_ACTIVITY, type: AttributeType.STRING }, sortKey: { - name: "nextActivityDate", + name: Attributes.NEXT_ACTIVITY_DATE, type: AttributeType.STRING }, projectionType: ProjectionType.KEYS_ONLY @@ -179,11 +202,11 @@ export class Dynamodb extends Construct { DatastoreTable.addGlobalSecondaryIndex({ indexName: "storeTimeDocRefTitle", partitionKey: { - name: "docRefTitle", + name: Attributes.DOC_REF_TITLE, type: AttributeType.STRING }, sortKey: { - name: "storeTime", + name: Attributes.STORE_TIME, type: AttributeType.STRING }, projectionType: ProjectionType.KEYS_ONLY @@ -192,11 +215,11 @@ export class Dynamodb extends Construct { DatastoreTable.addGlobalSecondaryIndex({ indexName: "backstopDeleteDate", partitionKey: { - name: "sk", + name: Attributes.SORT_KEY, type: AttributeType.STRING }, sortKey: { - name: "backstopDeleteDate", + name: Attributes.BACKSTOP_DELETE_DATE, type: AttributeType.STRING }, projectionType: ProjectionType.KEYS_ONLY @@ -205,11 +228,11 @@ export class Dynamodb extends Construct { DatastoreTable.addGlobalSecondaryIndex({ indexName: "prescriptionId", partitionKey: { - name: "prescriptionId", + name: Attributes.PRESCRIPTION_ID, type: AttributeType.STRING }, sortKey: { - name: "sk", + name: Attributes.SORT_KEY, type: AttributeType.STRING }, projectionType: ProjectionType.KEYS_ONLY @@ -218,7 +241,7 @@ export class Dynamodb extends Construct { DatastoreTable.addGlobalSecondaryIndex({ indexName: "claimIdSequenceNumber", partitionKey: { - name: "sequenceNumber", + name: Attributes.SEQUENCE_NUMBER, type: AttributeType.NUMBER }, projectionType: ProjectionType.KEYS_ONLY @@ -227,7 +250,7 @@ export class Dynamodb extends Construct { DatastoreTable.addGlobalSecondaryIndex({ indexName: "claimIdSequenceNumberNwssp", partitionKey: { - name: "sequenceNumberNwssp", + name: Attributes.SEQUENCE_NUMBER_NWSSP, type: AttributeType.NUMBER }, projectionType: ProjectionType.KEYS_ONLY From 463f6a71e1b5c5a48fa3e3f549f4d200c8cd657f Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Wed, 27 Nov 2024 12:10:34 +0000 Subject: [PATCH 03/10] parameterises keys --- packages/cdk/resources/Dynamodb.ts | 150 ++++++--------------------- packages/cdk/resources/attributes.ts | 62 +++++++++++ 2 files changed, 94 insertions(+), 118 deletions(-) create mode 100644 packages/cdk/resources/attributes.ts diff --git a/packages/cdk/resources/Dynamodb.ts b/packages/cdk/resources/Dynamodb.ts index c53d757..bb0e027 100644 --- a/packages/cdk/resources/Dynamodb.ts +++ b/packages/cdk/resources/Dynamodb.ts @@ -1,7 +1,6 @@ import {Construct} from "constructs" import { - AttributeType, Billing, ProjectionType, TableEncryptionV2, @@ -15,29 +14,7 @@ import { } from "aws-cdk-lib/aws-iam" import {Key} from "aws-cdk-lib/aws-kms" import {Duration, RemovalPolicy} from "aws-cdk-lib" - -enum Attributes { - PRIMARY_KEY = "pk", - SORT_KEY = "sk", - NHS_NUMBER = "nhsNumber", - CREATION_DATETIME = "creationDatetime", - INDEXES = "indexes", - PRESCRIBER_ORG = "prescriberOrg", - DISPENSER_ORG = "dispenserOrg", - NOMINATED_PHARMACY = "nominatedPharmacy", - IS_READY = "isReady", - STATUS = "status", - CLAIM_IDS = "claimIds", - NEXT_ACTIVITY = "nextActivity", - NEXT_ACTIVITY_DATE = "nextActivityDate", - DOC_REF_TITLE = "docRefTitle", - STORE_TIME = "storeTime", - BACKSTOP_DELETE_DATE = "backstopDeleteDate", - PRESCRIPTION_ID = "prescriptionId", - SEQUENCE_NUMBER = "sequenceNumber", - SEQUENCE_NUMBER_NWSSP = "sequenceNumberNwssp", - EXPIRE_AT = "expireAt" -} +import {ATTRIBUTE_KEYS, AttributeNames} from "./attributes" export interface DynamodbProps { readonly stackName: string @@ -89,170 +66,107 @@ export class Dynamodb extends Construct { // the table const DatastoreTable = new TableV2(this, "DatastoreTable", { - partitionKey: { - name: Attributes.PRIMARY_KEY, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.SORT_KEY, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.PRIMARY_KEY, + sortKey: ATTRIBUTE_KEYS.SORT_KEY, tableName: `${props.stackName}-datastore`, removalPolicy: props.allowAutoDeleteObjects ? RemovalPolicy.DESTROY: RemovalPolicy.RETAIN, pointInTimeRecovery: true, encryption: TableEncryptionV2.customerManagedKey(DatastoreKmsKey), billing: Billing.onDemand(), - timeToLiveAttribute: Attributes.EXPIRE_AT + timeToLiveAttribute: AttributeNames.EXPIRE_AT }) // global secondary indexes DatastoreTable.addGlobalSecondaryIndex({ indexName: "nhsNumberDate", - partitionKey: { - name: Attributes.NHS_NUMBER, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.CREATION_DATETIME, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.NHS_NUMBER, + sortKey: ATTRIBUTE_KEYS.CREATION_DATETIME, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - Attributes.INDEXES, - Attributes.PRESCRIBER_ORG, - Attributes.DISPENSER_ORG + AttributeNames.INDEXES, + AttributeNames.PRESCRIBER_ORG, + AttributeNames.DISPENSER_ORG ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "prescriberDate", - partitionKey: { - name: Attributes.PRESCRIBER_ORG, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.CREATION_DATETIME, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.PRESCRIBER_ORG, + sortKey: ATTRIBUTE_KEYS.CREATION_DATETIME, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - Attributes.INDEXES, - Attributes.DISPENSER_ORG + AttributeNames.INDEXES, + AttributeNames.DISPENSER_ORG ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "dispenserDate", - partitionKey: { - name: Attributes.DISPENSER_ORG, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.CREATION_DATETIME, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.DISPENSER_ORG, + sortKey: ATTRIBUTE_KEYS.CREATION_DATETIME, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - Attributes.INDEXES + AttributeNames.INDEXES ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "nominatedPharmacyStatus", - partitionKey: { - name: Attributes.NOMINATED_PHARMACY, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.IS_READY, - type: AttributeType.NUMBER - }, + partitionKey: ATTRIBUTE_KEYS.NOMINATED_PHARMACY, + sortKey: ATTRIBUTE_KEYS.IS_READY, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - Attributes.STATUS, - Attributes.INDEXES + AttributeNames.STATUS, + AttributeNames.INDEXES ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "claimId", - partitionKey: { - name: Attributes.SORT_KEY, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.SORT_KEY, projectionType: ProjectionType.INCLUDE, nonKeyAttributes: [ - Attributes.CLAIM_IDS + AttributeNames.CLAIM_IDS ] }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "nextActivityDate", - partitionKey: { - name: Attributes.NEXT_ACTIVITY, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.NEXT_ACTIVITY_DATE, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.NEXT_ACTIVITY, + sortKey: ATTRIBUTE_KEYS.NEXT_ACTIVITY_DATE, projectionType: ProjectionType.KEYS_ONLY }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "storeTimeDocRefTitle", - partitionKey: { - name: Attributes.DOC_REF_TITLE, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.STORE_TIME, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.DOC_REF_TITLE, + sortKey: ATTRIBUTE_KEYS.STORE_TIME, projectionType: ProjectionType.KEYS_ONLY }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "backstopDeleteDate", - partitionKey: { - name: Attributes.SORT_KEY, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.BACKSTOP_DELETE_DATE, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.SORT_KEY, + sortKey: ATTRIBUTE_KEYS.BACKSTOP_DELETE_DATE, projectionType: ProjectionType.KEYS_ONLY }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "prescriptionId", - partitionKey: { - name: Attributes.PRESCRIPTION_ID, - type: AttributeType.STRING - }, - sortKey: { - name: Attributes.SORT_KEY, - type: AttributeType.STRING - }, + partitionKey: ATTRIBUTE_KEYS.PRESCRIPTION_ID, + sortKey: ATTRIBUTE_KEYS.SORT_KEY, projectionType: ProjectionType.KEYS_ONLY }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "claimIdSequenceNumber", - partitionKey: { - name: Attributes.SEQUENCE_NUMBER, - type: AttributeType.NUMBER - }, + partitionKey: ATTRIBUTE_KEYS.SEQUENCE_NUMBER, projectionType: ProjectionType.KEYS_ONLY }) DatastoreTable.addGlobalSecondaryIndex({ indexName: "claimIdSequenceNumberNwssp", - partitionKey: { - name: Attributes.SEQUENCE_NUMBER_NWSSP, - type: AttributeType.NUMBER - }, + partitionKey: ATTRIBUTE_KEYS.SEQUENCE_NUMBER_NWSSP, projectionType: ProjectionType.KEYS_ONLY }) diff --git a/packages/cdk/resources/attributes.ts b/packages/cdk/resources/attributes.ts new file mode 100644 index 0000000..ef167d0 --- /dev/null +++ b/packages/cdk/resources/attributes.ts @@ -0,0 +1,62 @@ +import {AttributeType} from "aws-cdk-lib/aws-dynamodb" + +export enum AttributeNames { + PRIMARY_KEY = "pk", + SORT_KEY = "sk", + NHS_NUMBER = "nhsNumber", + CREATION_DATETIME = "creationDatetime", + INDEXES = "indexes", + PRESCRIBER_ORG = "prescriberOrg", + DISPENSER_ORG = "dispenserOrg", + NOMINATED_PHARMACY = "nominatedPharmacy", + IS_READY = "isReady", + STATUS = "status", + CLAIM_IDS = "claimIds", + NEXT_ACTIVITY = "nextActivity", + NEXT_ACTIVITY_DATE = "nextActivityDate", + DOC_REF_TITLE = "docRefTitle", + STORE_TIME = "storeTime", + BACKSTOP_DELETE_DATE = "backstopDeleteDate", + PRESCRIPTION_ID = "prescriptionId", + SEQUENCE_NUMBER = "sequenceNumber", + SEQUENCE_NUMBER_NWSSP = "sequenceNumberNwssp", + EXPIRE_AT = "expireAt" + } + + interface AttributeKey { + name: string + type: AttributeType + } + +const stringKey = (name: AttributeNames): AttributeKey => { + return { + name: name, + type: AttributeType.STRING + } +} + +const numberKey = (name: AttributeNames): AttributeKey => { + return { + name: name, + type: AttributeType.NUMBER + } +} + +export const ATTRIBUTE_KEYS = { + PRIMARY_KEY: stringKey(AttributeNames.PRIMARY_KEY), + NHS_NUMBER: stringKey(AttributeNames.NHS_NUMBER), + CREATION_DATETIME: stringKey(AttributeNames.CREATION_DATETIME), + PRESCRIBER_ORG: stringKey(AttributeNames.PRESCRIBER_ORG), + DISPENSER_ORG: stringKey(AttributeNames.DISPENSER_ORG), + NOMINATED_PHARMACY: stringKey(AttributeNames.NOMINATED_PHARMACY), + IS_READY: numberKey(AttributeNames.IS_READY), + SORT_KEY: stringKey(AttributeNames.SORT_KEY), + NEXT_ACTIVITY: stringKey(AttributeNames.NEXT_ACTIVITY), + NEXT_ACTIVITY_DATE: stringKey(AttributeNames.NEXT_ACTIVITY_DATE), + DOC_REF_TITLE: stringKey(AttributeNames.DOC_REF_TITLE), + STORE_TIME: stringKey(AttributeNames.STORE_TIME), + BACKSTOP_DELETE_DATE: stringKey(AttributeNames.BACKSTOP_DELETE_DATE), + PRESCRIPTION_ID: stringKey(AttributeNames.PRESCRIPTION_ID), + SEQUENCE_NUMBER: numberKey(AttributeNames.SEQUENCE_NUMBER), + SEQUENCE_NUMBER_NWSSP: numberKey(AttributeNames.SEQUENCE_NUMBER_NWSSP) +} From 447b97defa30462b2b76ee2fece20c0a92ffc5ec Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 13:17:22 +0000 Subject: [PATCH 04/10] updates service name --- .github/workflows/ci.yml | 4 ++-- .github/workflows/pull_request.yml | 2 +- .github/workflows/release.yml | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b36ef8..ad1f53a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,7 +98,7 @@ jobs: needs: [tag_release, package_code, get_commit_id] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources + SERVICE_NAME: spine-eps TARGET_ENVIRONMENT: dev VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -128,7 +128,7 @@ jobs: needs: [tag_release, release_dev, package_code, get_commit_id] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources + SERVICE_NAME: spine-eps TARGET_ENVIRONMENT: qa VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b7b8469..077a882 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -63,7 +63,7 @@ jobs: needs: [get_issue_number, package_code, get_commit_id, quality_checks] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources-pr-${{needs.get_issue_number.outputs.issue_number}} + SERVICE_NAME: spine-eps-pr-${{needs.get_issue_number.outputs.issue_number}} TARGET_ENVIRONMENT: dev-pr VERSION_NUMBER: PR-${{ needs.get_issue_number.outputs.issue_number }} COMMIT_ID: ${{ needs.get_commit_id.outputs.commit_id }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 88b728d..d6336a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -117,7 +117,7 @@ jobs: needs: [tag_release, package_code, get_commit_id] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources + SERVICE_NAME: spine-eps TARGET_ENVIRONMENT: dev VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -146,7 +146,7 @@ jobs: needs: [tag_release, package_code, get_commit_id, release_dev] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources + SERVICE_NAME: spine-eps TARGET_ENVIRONMENT: ref VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -160,7 +160,7 @@ jobs: needs: [tag_release, package_code, get_commit_id, release_dev] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources + SERVICE_NAME: spine-eps TARGET_ENVIRONMENT: qa VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -174,7 +174,7 @@ jobs: needs: [tag_release, package_code, get_commit_id, release_qa] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: storage-resources + SERVICE_NAME: spine-eps TARGET_ENVIRONMENT: int VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -188,7 +188,7 @@ jobs: # needs: [tag_release, package_code, get_commit_id, release_int] # uses: ./.github/workflows/cdk_release_code.yml # with: - # SERVICE_NAME: storage-resources + # SERVICE_NAME: spine-eps # TARGET_ENVIRONMENT: prod # VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} # COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} From 8e522b50de5d4be61559d59079df709a78c4a802 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 14:37:32 +0000 Subject: [PATCH 05/10] updates naming convention and parameterisation --- .github/workflows/cdk_release_code.yml | 6 ++++-- .github/workflows/ci.yml | 4 ++-- .github/workflows/pull_request.yml | 4 ++-- .github/workflows/release.yml | 10 +++++----- Makefile | 6 ++++-- packages/cdk/bin/StorageResourcesApp.ts | 5 ++++- packages/cdk/resources/Dynamodb.ts | 8 ++++---- packages/cdk/stacks/StorageResourcesStack.ts | 14 +++++++------- 8 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.github/workflows/cdk_release_code.yml b/.github/workflows/cdk_release_code.yml index efc97b9..22958d9 100644 --- a/.github/workflows/cdk_release_code.yml +++ b/.github/workflows/cdk_release_code.yml @@ -88,12 +88,14 @@ jobs: - name: fix cdk.json for deployment run: | jq \ - --arg serviceName "${{ inputs.SERVICE_NAME }}" \ + --arg SERVICE_NAME "${{ inputs.SERVICE_NAME }}" \ + --arg ENVIRONMENT "${{ inputs.TARGET_ENVIRONMENT }}" \ --arg VERSION_NUMBER "${{ inputs.VERSION_NUMBER }}" \ --arg COMMIT_ID "${{ inputs.COMMIT_ID }}" \ --argjson allowAutoDeleteObjects "${{ inputs.ALLOW_AUTO_DELETE_OBJECTS }}" \ '.context += { - "serviceName": $serviceName, + "SERVICE_NAME": $SERVICE_NAME, + "ENVIRONMENT": $ENVIRONMENT, "VERSION_NUMBER": $VERSION_NUMBER, "COMMIT_ID": $COMMIT_ID, "allowAutoDeleteObjects": $allowAutoDeleteObjects diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad1f53a..1b0b227 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,7 +98,7 @@ jobs: needs: [tag_release, package_code, get_commit_id] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps + SERVICE_NAME: eps-spine TARGET_ENVIRONMENT: dev VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -128,7 +128,7 @@ jobs: needs: [tag_release, release_dev, package_code, get_commit_id] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps + SERVICE_NAME: eps-spine TARGET_ENVIRONMENT: qa VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 077a882..b69a0ab 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -63,8 +63,8 @@ jobs: needs: [get_issue_number, package_code, get_commit_id, quality_checks] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps-pr-${{needs.get_issue_number.outputs.issue_number}} - TARGET_ENVIRONMENT: dev-pr + SERVICE_NAME: eps-spine + TARGET_ENVIRONMENT: dev-pr-${{needs.get_issue_number.outputs.issue_number}} VERSION_NUMBER: PR-${{ needs.get_issue_number.outputs.issue_number }} COMMIT_ID: ${{ needs.get_commit_id.outputs.commit_id }} CDK_APP_NAME: StorageResourcesApp diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d6336a8..75e6f8b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -117,7 +117,7 @@ jobs: needs: [tag_release, package_code, get_commit_id] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps + SERVICE_NAME: eps-spine TARGET_ENVIRONMENT: dev VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -146,7 +146,7 @@ jobs: needs: [tag_release, package_code, get_commit_id, release_dev] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps + SERVICE_NAME: eps-spine TARGET_ENVIRONMENT: ref VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -160,7 +160,7 @@ jobs: needs: [tag_release, package_code, get_commit_id, release_dev] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps + SERVICE_NAME: eps-spine TARGET_ENVIRONMENT: qa VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -174,7 +174,7 @@ jobs: needs: [tag_release, package_code, get_commit_id, release_qa] uses: ./.github/workflows/cdk_release_code.yml with: - SERVICE_NAME: spine-eps + SERVICE_NAME: eps-spine TARGET_ENVIRONMENT: int VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} @@ -188,7 +188,7 @@ jobs: # needs: [tag_release, package_code, get_commit_id, release_int] # uses: ./.github/workflows/cdk_release_code.yml # with: - # SERVICE_NAME: spine-eps + # SERVICE_NAME: eps-spine # TARGET_ENVIRONMENT: prod # VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}} # COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}} diff --git a/Makefile b/Makefile index 3fa4c40..5e29dc7 100644 --- a/Makefile +++ b/Makefile @@ -70,14 +70,15 @@ cdk-synth: --context VERSION_NUMBER=undefined \ --context COMMIT_ID=undefined -cdk-diff: guard-service_name +cdk-diff: guard-service_name guard-environment npx cdk diff \ --app "npx ts-node --prefer-ts-exts packages/cdk/bin/StorageResourcesApp.ts" \ --context serviceName=$$service_name \ + --context environment=$$ENVIRONMENT \ --context VERSION_NUMBER=$$VERSION_NUMBER \ --context COMMIT_ID=$$COMMIT_ID -cdk-watch: guard-service_name +cdk-watch: guard-service_name guard-environment REQUIRE_APPROVAL="$${REQUIRE_APPROVAL:-any-change}" && \ VERSION_NUMBER="$${VERSION_NUMBER:-undefined}" && \ COMMIT_ID="$${COMMIT_ID:-undefined}" && \ @@ -88,5 +89,6 @@ cdk-watch: guard-service_name --ci true \ --require-approval $${REQUIRE_APPROVAL} \ --context serviceName=$$service_name \ + --context environment=$$ENVIRONMENT \ --context VERSION_NUMBER=$$VERSION_NUMBER \ --context COMMIT_ID=$$COMMIT_ID diff --git a/packages/cdk/bin/StorageResourcesApp.ts b/packages/cdk/bin/StorageResourcesApp.ts index 921fb23..1fc6094 100644 --- a/packages/cdk/bin/StorageResourcesApp.ts +++ b/packages/cdk/bin/StorageResourcesApp.ts @@ -9,6 +9,9 @@ const app = new App() */ const serviceName = app.node.tryGetContext("serviceName") +const environment = app.node.tryGetContext("environment") +const stackPrefix = `nhse-${environment}-${serviceName}` + const version = app.node.tryGetContext("VERSION_NUMBER") const commit = app.node.tryGetContext("COMMIT_ID") @@ -23,6 +26,6 @@ new StorageResourcesStack(app, "StorageResourcesStack", { env: { region: "eu-west-2" }, - stackName: `${serviceName}`, + stackPrefix: stackPrefix, version: version }) diff --git a/packages/cdk/resources/Dynamodb.ts b/packages/cdk/resources/Dynamodb.ts index bb0e027..3060c0d 100644 --- a/packages/cdk/resources/Dynamodb.ts +++ b/packages/cdk/resources/Dynamodb.ts @@ -17,7 +17,7 @@ import {Duration, RemovalPolicy} from "aws-cdk-lib" import {ATTRIBUTE_KEYS, AttributeNames} from "./attributes" export interface DynamodbProps { - readonly stackName: string + readonly stackPrefix: string readonly account: string readonly region: string readonly allowAutoDeleteObjects: boolean @@ -41,8 +41,8 @@ export class Dynamodb extends Construct { const DatastoreKmsKey = new Key(this, "DatastoreKmsKey", { removalPolicy: RemovalPolicy.DESTROY, pendingWindow: Duration.days(7), - alias: `alias/${props.stackName}-DatastoreKmsKey`, - description: `${props.stackName}-DatastoreKmsKey`, + alias: `alias/${props.stackPrefix}-DatastoreKmsKey`, + description: `${props.stackPrefix}-DatastoreKmsKey`, enableKeyRotation: true }) @@ -68,7 +68,7 @@ export class Dynamodb extends Construct { const DatastoreTable = new TableV2(this, "DatastoreTable", { partitionKey: ATTRIBUTE_KEYS.PRIMARY_KEY, sortKey: ATTRIBUTE_KEYS.SORT_KEY, - tableName: `${props.stackName}-datastore`, + tableName: `${props.stackPrefix}-datastore`, removalPolicy: props.allowAutoDeleteObjects ? RemovalPolicy.DESTROY: RemovalPolicy.RETAIN, pointInTimeRecovery: true, encryption: TableEncryptionV2.customerManagedKey(DatastoreKmsKey), diff --git a/packages/cdk/stacks/StorageResourcesStack.ts b/packages/cdk/stacks/StorageResourcesStack.ts index 5992cd1..7318ffd 100644 --- a/packages/cdk/stacks/StorageResourcesStack.ts +++ b/packages/cdk/stacks/StorageResourcesStack.ts @@ -9,7 +9,7 @@ import {nagSuppressions} from "../nagSuppressions" import {Dynamodb} from "../resources/Dynamodb" export interface StorageResourcesStackProps extends StackProps{ - readonly stackName: string + readonly stackPrefix: string readonly version: string } @@ -29,7 +29,7 @@ export class StorageResourcesStack extends Stack { // Resources const dynamodb = new Dynamodb(this, "DynamoDB", { - stackName: props.stackName, + stackPrefix: props.stackPrefix, account: this.account, region: this.region, allowAutoDeleteObjects: allowAutoDeleteObjects @@ -40,23 +40,23 @@ export class StorageResourcesStack extends Stack { //Exports new CfnOutput(this, "tableWriteManagedPolicyArn", { value: dynamodb.tableWriteManagedPolicy.managedPolicyArn, - exportName: `${props.stackName}:tableWriteManagedPolicy:Arn` + exportName: `${props.stackPrefix}:tableWriteManagedPolicy:Arn` }) new CfnOutput(this, "tableReadManagedPolicyArn", { value: dynamodb.tableReadManagedPolicy.managedPolicyArn, - exportName: `${props.stackName}:tableReadManagedPolicy:Arn` + exportName: `${props.stackPrefix}:tableReadManagedPolicy:Arn` }) new CfnOutput(this, "usePrescriptionsTableKmsKeyPolicyArn", { value: dynamodb.usePrescriptionsTableKmsKeyPolicy.managedPolicyArn, - exportName: `${props.stackName}:usePrescriptionsTableKmsKeyPolicy:Arn` + exportName: `${props.stackPrefix}:usePrescriptionsTableKmsKeyPolicy:Arn` }) new CfnOutput(this, "DatastoreTableArn", { value: dynamodb.DatastoreTable.tableArn, - exportName: `${props.stackName}:DatastoreTable:Arn` + exportName: `${props.stackPrefix}:DatastoreTable:Arn` }) new CfnOutput(this, "DatastoreKmsKeyArn", { value: dynamodb.DatastoreKmsKey.keyArn, - exportName: `${props.stackName}:DatastoreKmsKey:Arn` + exportName: `${props.stackPrefix}:DatastoreKmsKey:Arn` }) nagSuppressions(this) } From 726be3418d7ae09a778b503dcf0f6c902969cefd Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 14:44:21 +0000 Subject: [PATCH 06/10] updates stack name --- packages/cdk/bin/StorageResourcesApp.ts | 2 +- packages/cdk/stacks/StorageResourcesStack.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cdk/bin/StorageResourcesApp.ts b/packages/cdk/bin/StorageResourcesApp.ts index 1fc6094..7833119 100644 --- a/packages/cdk/bin/StorageResourcesApp.ts +++ b/packages/cdk/bin/StorageResourcesApp.ts @@ -22,7 +22,7 @@ Tags.of(app).add("version", version) Tags.of(app).add("commit", commit) Tags.of(app).add("cdkApp", "StorageResourcesApp") -new StorageResourcesStack(app, "StorageResourcesStack", { +new StorageResourcesStack(app, { env: { region: "eu-west-2" }, diff --git a/packages/cdk/stacks/StorageResourcesStack.ts b/packages/cdk/stacks/StorageResourcesStack.ts index 7318ffd..6ce0446 100644 --- a/packages/cdk/stacks/StorageResourcesStack.ts +++ b/packages/cdk/stacks/StorageResourcesStack.ts @@ -18,8 +18,8 @@ export interface StorageResourcesStackProps extends StackProps{ */ export class StorageResourcesStack extends Stack { - public constructor(scope: App, id: string, props: StorageResourcesStackProps){ - super(scope, id, props) + public constructor(scope: App, props: StorageResourcesStackProps){ + super(scope, props.stackPrefix, props) // Context /* context values passed as --context cli arguments are passed as strings so coerce them to expected types*/ From 8ae8d04db736a2e6b5a8a147b45f634a275c6c74 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 14:54:48 +0000 Subject: [PATCH 07/10] makes param names consistent --- Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5e29dc7..5bd054a 100644 --- a/Makefile +++ b/Makefile @@ -67,18 +67,20 @@ cdk-synth: npx cdk synth \ --quiet \ --app "npx ts-node --prefer-ts-exts packages/cdk/bin/StorageResourcesApp.ts" \ + --context SERVICE_NAME=undefined \ + --context ENVIRONMENT=undefined \ --context VERSION_NUMBER=undefined \ --context COMMIT_ID=undefined -cdk-diff: guard-service_name guard-environment +cdk-diff: guard-SERVICE_NAME guard-ENVIRONMENT npx cdk diff \ --app "npx ts-node --prefer-ts-exts packages/cdk/bin/StorageResourcesApp.ts" \ - --context serviceName=$$service_name \ - --context environment=$$ENVIRONMENT \ + --context SERVICE_NAME=$$SERVICE_NAME \ + --context ENVIRONMENT=$$ENVIRONMENT \ --context VERSION_NUMBER=$$VERSION_NUMBER \ --context COMMIT_ID=$$COMMIT_ID -cdk-watch: guard-service_name guard-environment +cdk-watch: guard-SERVICE_NAME guard-ENVIRONMENT REQUIRE_APPROVAL="$${REQUIRE_APPROVAL:-any-change}" && \ VERSION_NUMBER="$${VERSION_NUMBER:-undefined}" && \ COMMIT_ID="$${COMMIT_ID:-undefined}" && \ @@ -88,7 +90,7 @@ cdk-watch: guard-service_name guard-environment --all \ --ci true \ --require-approval $${REQUIRE_APPROVAL} \ - --context serviceName=$$service_name \ - --context environment=$$ENVIRONMENT \ + --context SERVICE_NAME=$$SERVICE_NAME \ + --context ENVIRONMENT=$$ENVIRONMENT \ --context VERSION_NUMBER=$$VERSION_NUMBER \ --context COMMIT_ID=$$COMMIT_ID From c0646f934979465a529ef7a425f74cb5042fb6b3 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 14:56:11 +0000 Subject: [PATCH 08/10] makes param names consistent --- packages/cdk/bin/StorageResourcesApp.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cdk/bin/StorageResourcesApp.ts b/packages/cdk/bin/StorageResourcesApp.ts index 7833119..3505767 100644 --- a/packages/cdk/bin/StorageResourcesApp.ts +++ b/packages/cdk/bin/StorageResourcesApp.ts @@ -8,8 +8,8 @@ const app = new App() - logRetentionInDays */ -const serviceName = app.node.tryGetContext("serviceName") -const environment = app.node.tryGetContext("environment") +const serviceName = app.node.tryGetContext("SERVICE_NAME") +const environment = app.node.tryGetContext("ENVIRONMENT") const stackPrefix = `nhse-${environment}-${serviceName}` const version = app.node.tryGetContext("VERSION_NUMBER") From 8241bee8be44867fb808012414b0ba8cb20a4e3c Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 15:22:40 +0000 Subject: [PATCH 09/10] updates nag suppressions --- packages/cdk/nagSuppressions.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/cdk/nagSuppressions.ts b/packages/cdk/nagSuppressions.ts index 1c223ac..93df28e 100644 --- a/packages/cdk/nagSuppressions.ts +++ b/packages/cdk/nagSuppressions.ts @@ -6,7 +6,7 @@ import {NagPackSuppression, NagSuppressions} from "cdk-nag" export const nagSuppressions = (stack: Stack) => { safeAddNagSuppression( stack, - "/StorageResourcesStack/DynamoDB/TableReadManagedPolicy/Resource", + "/DynamoDB/TableReadManagedPolicy/Resource", [ { id: "AwsSolutions-IAM5", @@ -17,7 +17,7 @@ export const nagSuppressions = (stack: Stack) => { safeAddNagSuppression( stack, - "/StorageResourcesStack/DynamoDB/TableWriteManagedPolicy/Resource", + "/DynamoDB/TableWriteManagedPolicy/Resource", [ { id: "AwsSolutions-IAM5", @@ -30,10 +30,12 @@ export const nagSuppressions = (stack: Stack) => { const safeAddNagSuppression = (stack: Stack, path: string, suppressions: Array) => { try { - NagSuppressions.addResourceSuppressionsByPath(stack, path, suppressions) + const stack_id = stack.node.id + const full_path = `/${stack_id}${path}` + NagSuppressions.addResourceSuppressionsByPath(stack, full_path, suppressions) // eslint-disable-next-line @typescript-eslint/no-unused-vars } catch(err){ - console.log(`Could not find path ${path}`) + console.log(`Could not find path ${path} in stack ${stack.node.id}`) } } From 0a28904e0cb973978cab17b3d60827e28cadce37 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 2 Dec 2024 15:22:50 +0000 Subject: [PATCH 10/10] renames table --- packages/cdk/resources/Dynamodb.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cdk/resources/Dynamodb.ts b/packages/cdk/resources/Dynamodb.ts index 3060c0d..5fd83a3 100644 --- a/packages/cdk/resources/Dynamodb.ts +++ b/packages/cdk/resources/Dynamodb.ts @@ -68,7 +68,7 @@ export class Dynamodb extends Construct { const DatastoreTable = new TableV2(this, "DatastoreTable", { partitionKey: ATTRIBUTE_KEYS.PRIMARY_KEY, sortKey: ATTRIBUTE_KEYS.SORT_KEY, - tableName: `${props.stackPrefix}-datastore`, + tableName: `${props.stackPrefix}`, removalPolicy: props.allowAutoDeleteObjects ? RemovalPolicy.DESTROY: RemovalPolicy.RETAIN, pointInTimeRecovery: true, encryption: TableEncryptionV2.customerManagedKey(DatastoreKmsKey),