Skip to content

Commit

Permalink
CMDCT-4186 - cdk side, "import" by recreating dynamo tables so that t…
Browse files Browse the repository at this point in the history
…hey are retained (#15015)
  • Loading branch information
peoplespete committed Dec 31, 2024
1 parent c8a2a23 commit 1aef34a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
5 changes: 4 additions & 1 deletion deployment/import_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ cognito.UserPool -
./run destroy --stage <YOUR_BRANCH_NAME>
```

:warning: Make sure that all sls associated stacks have been fully destroyed before proceeding.


## From `jon-cdk` branch:


Expand All @@ -34,7 +37,7 @@ WITHOUT_IMPORTS=true ./run deploy --stage <YOUR_BRANCH_NAME>
```bash
WITH_IMPORTS=true PROJECT=seds cdk import --context stage=<YOUR_BRANCH_NAME> --force
```
As this import occurs you'll have to provide the information you gathered just before destroying the serverless stacks.
As this import occurs you'll have to provide the information you gathered just before destroying the serverless stacks. For the dynamo tables the default should be correct but read closely to be sure.

3. Run a deploy on that same imported resource set.

Expand Down
61 changes: 61 additions & 0 deletions deployment/stacks/with_imports/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Construct } from "constructs";
import { aws_dynamodb as dynamodb } from "aws-cdk-lib";
import { DynamoDBTable } from "../../constructs/dynamodb-table";

interface CreateDataComponentsProps {
scope: Construct;
stage: string;
}

export function createDataComponents(props: CreateDataComponentsProps) {
const { scope, stage } = props;

new DynamoDBTable(scope, "FormAnswers", {
stage,
name: "form-answers",
partitionKey: {
name: "answer_entry",
type: dynamodb.AttributeType.STRING,
},
gsi: {
indexName: "state-form-index",
partitionKey: {
name: "state_form",
type: dynamodb.AttributeType.STRING,
},
},
})
new DynamoDBTable(scope, "FormQuestions", {
stage,
name: "form-questions",
partitionKey: { name: "question", type: dynamodb.AttributeType.STRING },
})
new DynamoDBTable(scope, "FormTemplates", {
stage,
name: "form-templates",
partitionKey: { name: "year", type: dynamodb.AttributeType.NUMBER },
})
new DynamoDBTable(scope, "Forms", {
stage,
name: "forms",
partitionKey: { name: "form", type: dynamodb.AttributeType.STRING },
})
new DynamoDBTable(scope, "StateForms", {
stage,
name: "state-forms",
partitionKey: {
name: "state_form",
type: dynamodb.AttributeType.STRING,
},
})
new DynamoDBTable(scope, "States", {
stage,
name: "states",
partitionKey: { name: "state_id", type: dynamodb.AttributeType.STRING },
})
new DynamoDBTable(scope, "AuthUser", {
stage,
name: "auth-user",
partitionKey: { name: "userId", type: dynamodb.AttributeType.STRING },
})
}
5 changes: 5 additions & 0 deletions deployment/stacks/with_imports/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
StackProps,
} from "aws-cdk-lib";
import { DeploymentConfigProperties } from "../../deployment-config";
import { createDataComponents } from "./data";
import { createUiComponents } from "./ui";
import { createUiAuthComponents } from "./ui-auth";

Expand All @@ -19,6 +20,10 @@ export class WithImportsParentStack extends Stack {
stage,
} = props;

createDataComponents({
scope: this,
stage,
});
createUiComponents({scope: this});
createUiAuthComponents({
scope: this,
Expand Down

0 comments on commit 1aef34a

Please sign in to comment.