@cumulus/aws-client
Version:
Utilities for working with AWS
63 lines • 2.66 kB
JavaScript
/**
* @module CloudFormation
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCfStackParameterValues = exports.describeCfStackResources = exports.describeCfStack = void 0;
const pick_1 = __importDefault(require("lodash/pick"));
const services_1 = require("./services");
/**
* Describes a given CloudFormation stack
*
* See [CloudFormation.Stack](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFormation.html#describeStacks-property)
*
* @param {string} StackName - The name of the CloudFormation stack to query
* @returns {Promise<CloudFormation.Stack>} The resources belonging to the stack
*/
const describeCfStack = async (StackName) => {
const response = await (0, services_1.cf)().describeStacks({ StackName });
if (response.Stacks)
return response.Stacks[0];
throw new Error(`Stack not found: ${StackName}`);
};
exports.describeCfStack = describeCfStack;
/**
* Describes the resources belonging to a given CloudFormation stack
*
* See [CloudFormation.StackResources](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFormation.html#describeStackResources-property)
*
* @param {string} StackName - The name of the CloudFormation stack to query
* @returns {Promise<CloudFormation.StackResources>} The resources belonging to the stack
*/
const describeCfStackResources = async (StackName) => {
const response = await (0, services_1.cf)().describeStackResources({ StackName });
return response.StackResources;
};
exports.describeCfStackResources = describeCfStackResources;
/**
* Get parameter values for the given CloudFormation stack
*
* @param {string} stackName - The name of the CloudFormation stack to query
* @param {Array<string>} parameterKeys - Key names for the stack parameters that you want to return
* @returns {Promise<Object>} Object keyed by parameter names
*/
const getCfStackParameterValues = async (stackName, parameterKeys) => {
let response;
try {
response = await (0, exports.describeCfStack)(stackName);
}
catch (error) {
return {};
}
const parameters = (response.Parameters || []).reduce((acc, { ParameterKey, ParameterValue }) => {
if (ParameterKey && ParameterValue)
return { ...acc, [ParameterKey]: ParameterValue };
return acc;
}, {});
return (0, pick_1.default)(parameters, parameterKeys);
};
exports.getCfStackParameterValues = getCfStackParameterValues;
//# sourceMappingURL=CloudFormation.js.map
;