Skip to content

Commit

Permalink
Merge pull request #616 from magieno/add-change-sets-cloudformation
Browse files Browse the repository at this point in the history
- Added throttling.
  • Loading branch information
etiennenoel authored Nov 28, 2023
2 parents 9d316d7 + 812099f commit aef4860
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/aws/src/clients/cloudformation.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ export class CloudformationClient implements CloudformationClientInterface {
/**
* Describes a Change Set.
* @param input The input to describe a change set.
* @param retryNumber
*/
async describeChangeSet(input: DescribeChangeSetCommandInput): Promise<DescribeChangeSetCommandOutput> {
async describeChangeSet(input: DescribeChangeSetCommandInput, retryNumber = 0): Promise<DescribeChangeSetCommandOutput> {
this.logHandler.debug("CLOUDFORMATION CLIENT - Describe Change Set", {input}, AwsModuleKeyname);
const command = new DescribeChangeSetCommand(input)
try {
return await this.getClient().send(command);
} catch (e) {
if(e.code === "Throttling" && retryNumber < 3) {
await new Promise(resolve => setTimeout(resolve, (retryNumber + 1) * 1000));

return this.describeChangeSet(input, retryNumber++);
}
this.logHandler.error("Error describing change set in cloudformation", {error: e}, AwsModuleKeyname);
throw e;
}
Expand All @@ -228,13 +234,19 @@ export class CloudformationClient implements CloudformationClientInterface {
/**
* Executes a Change Set.
* @param input The input to execute a change set.
* @param retryNumber
*/
async executeChangeSet(input: ExecuteChangeSetCommandInput): Promise<ExecuteChangeSetCommandOutput> {
async executeChangeSet(input: ExecuteChangeSetCommandInput, retryNumber = 0): Promise<ExecuteChangeSetCommandOutput> {
this.logHandler.debug("CLOUDFORMATION CLIENT - Execute Change Set", {input}, AwsModuleKeyname);
const command = new ExecuteChangeSetCommand(input)
try {
return await this.getClient().send(command);
} catch (e) {
if(e.code === "Throttling" && retryNumber < 3) {
await new Promise(resolve => setTimeout(resolve, (retryNumber + 1) * 1000));

return this.executeChangeSet(input, retryNumber++);
}
this.logHandler.error("Error executing change set in cloudformation", {error: e}, AwsModuleKeyname);
throw e;
}
Expand Down

0 comments on commit aef4860

Please sign in to comment.