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 21 22 23 24 25 26 27 28 29 | 3x 3x 3x 3x 2x 2x 2x 1x 1x 2x 2x 2x 1x 1x | 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}`);
const message =
error instanceof Error && error.message
? error.message
: (error?.toString?.() ?? "UnknownError");
if (message.includes(`Export with name ${exportName} does not exist.`)) {
throw new Error(message);
}
throw new Error("UnknownError");
}
}
|