UNPKG

ask-cli

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

118 lines (117 loc) 4.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const client_cloudformation_1 = require("@aws-sdk/client-cloudformation"); const ramda_1 = __importDefault(require("ramda")); const abstract_aws_client_1 = __importDefault(require("./abstract-aws-client")); /** * Class for AWS Cloudformation Client */ class CloudformationClient extends abstract_aws_client_1.default { /** * Constructor * @param configuration The AWS client config */ constructor(configuration) { super(configuration); this.client = new client_cloudformation_1.CloudFormationClient({ credentials: this.credentials, region: this.region, }); } /** * Creates a stack based on the parameters. * @param stackName The stack name * @param templateBody The template body * @param parameters The input parameters * @param capabilities The input capabilities */ createStack(stackName, templateBody, parameters, capabilities) { const command = new client_cloudformation_1.CreateStackCommand({ StackName: stackName, TemplateBody: templateBody, Capabilities: capabilities, ...(!ramda_1.default.isEmpty(parameters) && { Parameters: parameters }), }); return this.client.send(command).then((data) => data.StackId); } /** * Updates the stack based on the stackName with input parameters. * @param stackName The stack name * @param templateBody The template body * @param parameters The input parameters * @param capabilities The input capabilities */ updateStack(stackName, templateBody, parameters, capabilities) { const command = new client_cloudformation_1.UpdateStackCommand({ StackName: stackName, TemplateBody: templateBody, Capabilities: capabilities, ...(!ramda_1.default.isEmpty(parameters) && { Parameters: parameters }), }); return this.client .send(command) .then((data) => data.StackId) .catch((err) => { if (err.name !== "ValidationError" || err.message !== "No updates are to be performed.") { throw err; } }); } /** * Checks if stack exists * @param stackName The stack name */ stackExists(stackName) { return stackName ? this.getStack(stackName) .then((data) => data !== undefined && data.StackStatus !== "DELETE_COMPLETE") .catch(() => false) : Promise.resolve(false); } /** * Returns information for a stack * @param stackName The stack name */ getStack(stackName) { const command = new client_cloudformation_1.DescribeStacksCommand({ StackName: stackName, }); return this.client.send(command).then((data) => { var _a; return (_a = data.Stacks) === null || _a === void 0 ? void 0 : _a[0]; }); } /** * Returns all events for a stack * @param stackName The stack name */ getStackEvents(stackName) { const command = new client_cloudformation_1.DescribeStackEventsCommand({ StackName: stackName, }); return this.client.send(command).then((data) => data.StackEvents); } /** * Returns a specific resource for a stack * @param stackName The stack name * @param logicalId The logical resource ID */ getStackResource(stackName, logicalId) { const command = new client_cloudformation_1.DescribeStackResourceCommand({ StackName: stackName, LogicalResourceId: logicalId, }); return this.client.send(command).then((data) => data.StackResourceDetail); } /** * Returns all the resources for a stack * @param stackName The stack name */ getStackResources(stackName) { const command = new client_cloudformation_1.DescribeStackResourcesCommand({ StackName: stackName, }); return this.client.send(command).then((data) => data.StackResources); } } exports.default = CloudformationClient;