Skip to content

Commit

Permalink
refactor: simplify cfn output logic
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Oct 29, 2023
1 parent 0b375fd commit ed87f47
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions infra/util/cloud.formation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ import { CloudFormation } from '@aws-sdk/client-cloudformation';
export async function getCfnOutputs(stackName: string): Promise<Record<string, string>> {
const cfn = new CloudFormation();
const searchStacks = await cfn.describeStacks({ StackName: stackName });
cfn.listExports;
const outputs: Record<string, string> = {};
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;
}

0 comments on commit ed87f47

Please sign in to comment.