diff --git a/packages/aws/package-lock.json b/packages/aws/package-lock.json index 0ca4b44e9..32be1376a 100644 --- a/packages/aws/package-lock.json +++ b/packages/aws/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@pristine-ts/aws", - "version": "0.0.247", + "version": "0.0.248", "license": "ISC", "dependencies": { "@aws-sdk/client-cloudformation": "^3.211.0", @@ -29,7 +29,7 @@ }, "../common": { "name": "@pristine-ts/common", - "version": "0.0.247", + "version": "0.0.248", "license": "ISC", "dependencies": { "reflect-metadata": "^0.1.13", @@ -38,7 +38,7 @@ }, "../core": { "name": "@pristine-ts/core", - "version": "0.0.247", + "version": "0.0.248", "license": "ISC", "dependencies": { "@pristine-ts/common": "file:../common", @@ -54,7 +54,7 @@ }, "../logging": { "name": "@pristine-ts/logging", - "version": "0.0.247", + "version": "0.0.248", "license": "ISC", "dependencies": { "@pristine-ts/common": "file:../common", @@ -64,7 +64,7 @@ }, "../networking": { "name": "@pristine-ts/networking", - "version": "0.0.247", + "version": "0.0.248", "license": "ISC", "dependencies": { "@pristine-ts/common": "file:../common", @@ -76,7 +76,7 @@ }, "../security": { "name": "@pristine-ts/security", - "version": "0.0.247", + "version": "0.0.248", "license": "ISC", "dependencies": { "@pristine-ts/common": "file:../common", diff --git a/packages/aws/src/clients/cloudformation.client.ts b/packages/aws/src/clients/cloudformation.client.ts index 88c2222d2..80f9f4b6a 100644 --- a/packages/aws/src/clients/cloudformation.client.ts +++ b/packages/aws/src/clients/cloudformation.client.ts @@ -60,7 +60,7 @@ export class CloudformationClient implements CloudformationClientInterface { * Gets the description and all its details from a Cloudformation stack. * @param stackName The stack name to get the. */ - async getStackDescription(stackName: string): Promise { + async getStackDescription(stackName: string): Promise { this.logHandler.debug("CLOUDFORMATION CLIENT - Getting stack information", {stackName}, AwsModuleKeyname); const command = new DescribeStacksCommand({ StackName: stackName, @@ -68,10 +68,10 @@ export class CloudformationClient implements CloudformationClientInterface { try { const response: DescribeStacksCommandOutput = await this.getClient().send(command); if(!response.Stacks || response.Stacks.length < 1){ - throw new Error("No stacks were returned from cloudformation"); + return undefined; } if(response.Stacks.length > 1){ - throw new Error("More than one stack was returned from cloudformation"); + this.logHandler.warning("More than one stack was returned from cloudformation"); } return response.Stacks[0]; } catch (e) { @@ -80,6 +80,21 @@ export class CloudformationClient implements CloudformationClientInterface { } } + /** + * Gets the description and all its details from all the CloudFormation stacks. + */ + async listStacks(): Promise { + this.logHandler.debug("CLOUDFORMATION CLIENT - Getting list of stacks", {}, AwsModuleKeyname); + const command = new DescribeStacksCommand({}) + try { + const response: DescribeStacksCommandOutput = await this.getClient().send(command); + return response.Stacks ?? []; + } catch (e) { + this.logHandler.error("Error getting stack description from cloudformation", {error: e}, AwsModuleKeyname); + throw e; + } + } + /** * Creates a new stack in Cloudformation. * @param input The input to create the new stack. diff --git a/packages/aws/src/interfaces/cloudformation-client.interface.ts b/packages/aws/src/interfaces/cloudformation-client.interface.ts index b836768d3..834e1db02 100644 --- a/packages/aws/src/interfaces/cloudformation-client.interface.ts +++ b/packages/aws/src/interfaces/cloudformation-client.interface.ts @@ -29,7 +29,12 @@ export interface CloudformationClientInterface { * Gets the description and all its details from a Cloudformation stack. * @param stackName The stack name to get the. */ - getStackDescription(stackName: string): Promise; + getStackDescription(stackName: string): Promise; + + /** + * Gets the description and all its details from all the CloudFormation stacks. + */ + listStacks(): Promise; /** * Creates a new stack in Cloudformation.