Skip to content

Commit 133dc98

Browse files
authored
fix(toolkit): increase number of retries (#2053)
This will help in situations where the default retry behavior is not enough to cover throttling errors. Fixes #1647.
1 parent 4941ad2 commit 133dc98

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/aws-cdk/lib/api/bootstrap-environment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function bootstrapEnvironment(environment: Environment, aws: SDK, t
1212
environment,
1313
metadata: {},
1414
template: {
15-
Description: "The CDK Toolkit Stack. It cas created by `cdk bootstrap` and manages resources necessary for managing your Cloud Applications with AWS CDK.",
15+
Description: "The CDK Toolkit Stack. It was created by `cdk bootstrap` and manages resources necessary for managing your Cloud Applications with AWS CDK.",
1616
Resources: {
1717
StagingBucket: {
1818
Type: "AWS::S3::Bucket",

packages/aws-cdk/lib/api/util/sdk.ts

+18
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export class SDK {
5050
private readonly credentialsCache: CredentialsCache;
5151
private readonly profile?: string;
5252

53+
/**
54+
* Default retry options for SDK clients
55+
*
56+
* Biggest bottleneck is CloudFormation, with a 1tps call rate. We want to be
57+
* a little more tenacious than the defaults, and with a little more breathing
58+
* room between calls (defaults are {retries=3, base=100}).
59+
*
60+
* I've left this running in a tight loop for an hour and the throttle errors
61+
* haven't escaped the retry mechanism.
62+
*/
63+
private readonly retryOptions = { maxRetries: 6, retryDelayOptions: { base: 300 }};
64+
5365
constructor(options: SDKOptions = {}) {
5466
this.profile = options.profile;
5567

@@ -78,41 +90,47 @@ export class SDK {
7890

7991
public async cloudFormation(environment: Environment, mode: Mode): Promise<AWS.CloudFormation> {
8092
return new AWS.CloudFormation({
93+
...this.retryOptions,
8194
region: environment.region,
8295
credentials: await this.credentialsCache.get(environment.account, mode)
8396
});
8497
}
8598

8699
public async ec2(awsAccountId: string | undefined, region: string | undefined, mode: Mode): Promise<AWS.EC2> {
87100
return new AWS.EC2({
101+
...this.retryOptions,
88102
region,
89103
credentials: await this.credentialsCache.get(awsAccountId, mode)
90104
});
91105
}
92106

93107
public async ssm(awsAccountId: string | undefined, region: string | undefined, mode: Mode): Promise<AWS.SSM> {
94108
return new AWS.SSM({
109+
...this.retryOptions,
95110
region,
96111
credentials: await this.credentialsCache.get(awsAccountId, mode)
97112
});
98113
}
99114

100115
public async s3(environment: Environment, mode: Mode): Promise<AWS.S3> {
101116
return new AWS.S3({
117+
...this.retryOptions,
102118
region: environment.region,
103119
credentials: await this.credentialsCache.get(environment.account, mode)
104120
});
105121
}
106122

107123
public async route53(awsAccountId: string | undefined, region: string | undefined, mode: Mode): Promise<AWS.Route53> {
108124
return new AWS.Route53({
125+
...this.retryOptions,
109126
region,
110127
credentials: await this.credentialsCache.get(awsAccountId, mode),
111128
});
112129
}
113130

114131
public async ecr(environment: Environment, mode: Mode): Promise<AWS.ECR> {
115132
return new AWS.ECR({
133+
...this.retryOptions,
116134
region: environment.region,
117135
credentials: await this.credentialsCache.get(environment.account, mode)
118136
});

0 commit comments

Comments
 (0)