All files / lib/packages/shared-utils cloudformation.ts

100% Statements 14/14
75% Branches 6/8
75% Functions 3/4
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20      3x 3x   3x 3x 2x 2x 2x 1x   1x   2x 2x      
import { CloudFormationClient, ListExportsCommand } from "@aws-sdk/client-cloudformation";
 
export async function getExport(exportName: string, region: string = "us-east-1"): Promise<string> {
  const client = new CloudFormationClient({ region });
  const command = new ListExportsCommand({});
 
  try {
    const response = await client.send(command);
    const exports = response.Exports || [];
    const exportItem = exports.find((exp) => exp.Name === exportName);
    if (!exportItem) {
      throw new Error(`Export with name ${exportName} does not exist.`);
    }
    return exportItem.Value!;
  } catch (error) {
    console.error(`Error getting export value: ${error}`);
    throw error;
  }
}