Skip to content

Commit 6730f11

Browse files
feat(core): Adding "storeAllOutputs" property in SM input (aws-samples#554)
- Adding "storeAllOutputs" property in SM Input which will load all outputs from cfn stacks to DDB tables irrespective of existing entries.
1 parent 0820a9e commit 6730f11

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/core/cdk/src/initial-setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export namespace InitialSetup {
155155
s3Bucket: props.configS3Bucket,
156156
branchName: props.configBranchName,
157157
acceleratorVersion: props.acceleratorVersion!,
158+
'inputConfig.$': '$',
158159
},
159160
resultPath: '$.configuration',
160161
});
@@ -185,6 +186,7 @@ export namespace InitialSetup {
185186
'configCommitId.$': '$.configuration.configCommitId',
186187
'acceleratorVersion.$': '$.configuration.acceleratorVersion',
187188
outputTableName: outputsTable.tableName,
189+
'storeAllOutputs.$': '$.configuration.storeAllOutputs',
188190
},
189191
resultPath: '$.configuration.baselineOutput',
190192
});

src/core/runtime/src/get-baseline-step.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface GetBaseLineInput {
77
configCommitId: string;
88
outputTableName: string;
99
acceleratorVersion?: string;
10+
storeAllOutputs?: boolean;
1011
}
1112

1213
export interface ConfigurationOrganizationalUnit {
@@ -27,7 +28,7 @@ export const handler = async (input: GetBaseLineInput): Promise<GetBaseelineOutp
2728
console.log(`Loading configuration...`);
2829
console.log(JSON.stringify(input, null, 2));
2930

30-
const { configFilePath, configRepositoryName, configCommitId, outputTableName } = input;
31+
const { configFilePath, configRepositoryName, configCommitId, outputTableName, storeAllOutputs } = input;
3132

3233
// Retrieve Configuration from Code Commit with specific commitId
3334
const config = await loadAcceleratorConfig({
@@ -47,11 +48,25 @@ export const handler = async (input: GetBaseLineInput): Promise<GetBaseelineOutp
4748
throw new Error(`Both "alz-baseline" and "ct-baseline" can't be true`);
4849
}
4950

50-
// Checking whether DynamoDB outputs table is empty or not
51-
const storeAllOutputs = await dynamoDB.isEmpty(outputTableName);
51+
let runStoreAllOutputs: boolean = !!storeAllOutputs;
52+
if (!runStoreAllOutputs) {
53+
// Checking whether DynamoDB outputs table is empty or not
54+
runStoreAllOutputs = await dynamoDB.isEmpty(outputTableName);
55+
}
56+
console.log(
57+
JSON.stringify(
58+
{
59+
baseline,
60+
storeAllOutputs: runStoreAllOutputs,
61+
phases: [-1, 0, 1, 2, 3],
62+
},
63+
null,
64+
2,
65+
),
66+
);
5267
return {
5368
baseline,
54-
storeAllOutputs,
69+
storeAllOutputs: runStoreAllOutputs,
5570
phases: [-1, 0, 1, 2, 3],
5671
};
5772
};

src/core/runtime/src/get-or-create-config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ interface GetOrCreateConfigInput {
88
s3Bucket: string;
99
branchName: string;
1010
acceleratorVersion?: string;
11+
// Taking entire input to replace any default paramaters in SM Input
12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13+
inputConfig?: any;
1114
}
1215

1316
const codecommit = new CodeCommit();
@@ -17,7 +20,8 @@ export const handler = async (input: GetOrCreateConfigInput) => {
1720
console.log(`Get or Create Config from S3 file...`);
1821
console.log(JSON.stringify(input, null, 2));
1922

20-
const { repositoryName, s3Bucket, branchName, acceleratorVersion } = input;
23+
const { repositoryName, s3Bucket, branchName, acceleratorVersion, inputConfig } = input;
24+
const storeAllOutputs: boolean = !!inputConfig.storeAllOutputs;
2125
const configRepository = await codecommit.batchGetRepositories([repositoryName]);
2226
if (!configRepository.repositories || configRepository.repositories?.length === 0) {
2327
console.log(`Creating repository "${repositoryName}" for Config file`);
@@ -58,6 +62,7 @@ export const handler = async (input: GetOrCreateConfigInput) => {
5862
{
5963
...s3LoadResponse,
6064
acceleratorVersion,
65+
storeAllOutputs,
6166
},
6267
null,
6368
2,
@@ -66,6 +71,7 @@ export const handler = async (input: GetOrCreateConfigInput) => {
6671
return {
6772
...s3LoadResponse,
6873
acceleratorVersion,
74+
storeAllOutputs,
6975
};
7076
}
7177
const currentCommit = await codecommit.getBranch(repositoryName, branchName);
@@ -107,6 +113,7 @@ export const handler = async (input: GetOrCreateConfigInput) => {
107113
configCommitId: configCommitId || currentCommit.branch?.commitId,
108114
acceleratorVersion,
109115
configRootFilePath: filePath,
116+
storeAllOutputs,
110117
},
111118
null,
112119
2,
@@ -119,6 +126,7 @@ export const handler = async (input: GetOrCreateConfigInput) => {
119126
configCommitId: configCommitId || currentCommit.branch?.commitId,
120127
acceleratorVersion,
121128
configRootFilePath: filePath,
129+
storeAllOutputs,
122130
};
123131
} catch (e) {
124132
if (e.code !== 'FileDoesNotExistException' && e.code !== 'CommitDoesNotExistException') {
@@ -135,6 +143,7 @@ export const handler = async (input: GetOrCreateConfigInput) => {
135143
{
136144
...s3LoadResponse,
137145
acceleratorVersion,
146+
storeAllOutputs,
138147
},
139148
null,
140149
2,
@@ -144,6 +153,7 @@ export const handler = async (input: GetOrCreateConfigInput) => {
144153
return {
145154
...s3LoadResponse,
146155
acceleratorVersion,
156+
storeAllOutputs,
147157
};
148158
}
149159
};

0 commit comments

Comments
 (0)