From ed87f4798651bdf61facc7df4084ed4a8f611277 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 30 Oct 2023 10:30:05 +1300 Subject: [PATCH] refactor: simplify cfn output logic --- infra/util/cloud.formation.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/infra/util/cloud.formation.ts b/infra/util/cloud.formation.ts index 618a3f136..04cb10dde 100644 --- a/infra/util/cloud.formation.ts +++ b/infra/util/cloud.formation.ts @@ -3,21 +3,12 @@ import { CloudFormation } from '@aws-sdk/client-cloudformation'; export async function getCfnOutputs(stackName: string): Promise> { const cfn = new CloudFormation(); const searchStacks = await cfn.describeStacks({ StackName: stackName }); - cfn.listExports; const outputs: Record = {}; - const stacks = (searchStacks && searchStacks.Stacks) || []; - const stack = stacks.find((s) => s.StackName === stackName); + const stack = searchStacks?.Stacks?.find((s) => s.StackName === stackName); + if (stack?.Outputs == null) throw new Error(`Unable to find stack "${stackName}"`); - if (!stack) { - throw new Error(`Unable to find stack "${stackName}"`); - } - if (!stack.Outputs) { - throw new Error(`There is no output for stack "${stackName}"`); - } stack.Outputs.forEach(({ OutputKey, OutputValue }) => { - if (OutputKey && OutputValue) { - outputs[OutputKey] = OutputValue; - } + if (OutputKey != null && OutputValue != null) outputs[OutputKey] = OutputValue; }); return outputs; }