From dd25223fd05658ccb2d10d11ca93eea97647855c Mon Sep 17 00:00:00 2001 From: Etienne Noel Date: Mon, 16 Oct 2023 10:35:17 -0700 Subject: [PATCH 1/3] - Update. --- packages/aws/package-lock.json | 12 +++++------ .../aws/src/clients/cloudformation.client.ts | 21 ++++++++++++++++--- .../cloudformation-client.interface.ts | 7 ++++++- 3 files changed, 30 insertions(+), 10 deletions(-) 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..8eac9ccb9 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..2a048e019 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. From b802a76efde0f78007d7b13d16f906d2d2805d20 Mon Sep 17 00:00:00 2001 From: Etienne Noel Date: Tue, 17 Oct 2023 21:27:40 -0700 Subject: [PATCH 2/3] - Update. --- packages/aws/src/clients/cloudformation.client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws/src/clients/cloudformation.client.ts b/packages/aws/src/clients/cloudformation.client.ts index 8eac9ccb9..80f9f4b6a 100644 --- a/packages/aws/src/clients/cloudformation.client.ts +++ b/packages/aws/src/clients/cloudformation.client.ts @@ -83,12 +83,12 @@ export class CloudformationClient implements CloudformationClientInterface { /** * Gets the description and all its details from all the CloudFormation stacks. */ - async listStacks(): Promise { + 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; + return response.Stacks ?? []; } catch (e) { this.logHandler.error("Error getting stack description from cloudformation", {error: e}, AwsModuleKeyname); throw e; From 73e7e62680cf592dd0b265daf5189a9a70b92ede Mon Sep 17 00:00:00 2001 From: Etienne Noel Date: Tue, 17 Oct 2023 21:28:01 -0700 Subject: [PATCH 3/3] - update. --- packages/aws/src/interfaces/cloudformation-client.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws/src/interfaces/cloudformation-client.interface.ts b/packages/aws/src/interfaces/cloudformation-client.interface.ts index 2a048e019..834e1db02 100644 --- a/packages/aws/src/interfaces/cloudformation-client.interface.ts +++ b/packages/aws/src/interfaces/cloudformation-client.interface.ts @@ -34,7 +34,7 @@ export interface CloudformationClientInterface { /** * Gets the description and all its details from all the CloudFormation stacks. */ - listStacks(): Promise; + listStacks(): Promise; /** * Creates a new stack in Cloudformation.