Repository navigation
Conversation
…nment variables We pass an explicit retryStrategy to every SDK client, which makes the SDK ignore the standard AWS_MAX_ATTEMPTS and AWS_RETRY_MODE environment variables. Resolve them ourselves and fall back to the existing per-client defaults. The backoff schedule stays ours in both standard and adaptive mode.
In addition to the AWS_MAX_ATTEMPTS and AWS_RETRY_MODE environment variables, read max_attempts and retry_mode from the active profile in the shared config files, the way the AWS CLI does. Environment variables take precedence, and ~/.aws/config takes precedence over ~/.aws/credentials. Unlike region, there is no fallback to the default profile. BaseCredentials.awsCliCompatible() resolves the settings using the same profile as credentials and region, and returns them in a new optional SdkBaseConfig.retry field. SdkProvider passes them to every SDK. Custom and none() base credentials fall back to the environment variables only.
…m from the config file only Parse max_attempts / AWS_MAX_ATTEMPTS with parseInt and only reject values that are not a number, and treat any retry mode other than 'adaptive' as standard, matching the JavaScript SDK. Previously we rejected values the SDK accepts, such as '1.5', '0' or 'legacy'. Read retry_mode and max_attempts from ~/.aws/config only. The credentials file may only hold credentials, and the retry settings are documented for the config file only. This supersedes the config-over-credentials precedence described in the previous commit. Split the profile lookup into retrySettingsFromConfig(), and rename retrySettingsFromEnvAndProfile() to retrySettings().
…y strategy Pass the retry mode through as is and reject unknown values in sdkRetryStrategy(), accepting only 'standard' and 'adaptive' like the AWS CLI v2 does. This supersedes the previous commit, which silently treated any mode other than 'adaptive' as standard like the JavaScript SDK. Parse max attempts with parseInt and reject NaN in sdkRetryStrategy() as well. An explicit retryStrategy bypasses the SDK's own validation, and a NaN max attempts would otherwise silently disable retries. SdkRetrySettings.mode is now a string. Error messages no longer say where a value came from, matching the AWS CLI.
…tings() Retry settings are now resolved in one way only: retrySettings(profile) reads the environment variables and the profile in ~/.aws/config together. The separate environment and config file readers are no longer exported. SdkProvider no longer falls back to the environment variables when it is not given retry settings, which ignored the profile. SdkProviderOptions.retry and the SDK constructor's retrySettings parameter are now required. Toolkit resolves the settings with the AWS_PROFILE or default profile when the base credentials don't provide them, as with BaseCredentials.custom() and none(). Also fix the test build: ConfiguredRetryStrategy exposes the max attempts as maxAttempts() rather than maxAttemptsProvider().
…lient its own retry strategy Validate AWS_MAX_ATTEMPTS / max_attempts and AWS_RETRY_MODE / retry_mode in retrySettings(), when the values are read, instead of when an SDK client is created. SDK clients are first created inside credential resolution, whose error handling turned an invalid setting into a misleading "no credentials" or "could not assume role" error. Only the value that is used is validated, and the error quotes it. This supersedes the validation in sdkRetryStrategy() from an earlier commit, and SdkRetrySettings.mode is a 'standard' | 'adaptive' union again. Accept retry mode 'legacy' with a warning and use standard mode. It is a documented mode that other SDKs support, so users may have it configured for other tools; rejecting it would fail every command after upgrading. Build a retry strategy per SDK client instead of sharing one across all clients. The strategy holds the retry quota and, in adaptive mode, the client-side rate limiter, so throttling on one service slowed down calls to every other service. Trim the retry tests to the ones that cover our own logic.
Reject retry mode 'legacy' instead of warning and falling back to standard: the AWS CLI v2 rejects it too, so a value like that is already broken for the user. This supersedes the 'legacy' handling from the previous commit. An environment variable that is set, even to an empty string, now always takes precedence over the profile, and empty values are invalid, as in the AWS CLI v2. Max attempts must be a whole number of at least 1; '3x', '1.5', '0' and '-1' are rejected instead of being parsed with parseInt. retrySettings() reads the values and checks them with validateMaxAttempts() and validateMode(). SdkRetrySettings.mode stays a 'standard' | 'adaptive' union.
…retry 4.3.0 The STS client's backoff was an uncapped 100ms * 2^attempt. That was fine with the fixed 3 attempts, but users can now raise max attempts, and with AWS_MAX_ATTEMPTS=15 the last wait alone is about 27 minutes. Use cappedExponentialBackoff(100, 15_000) like the other clients. Require @smithy/util-retry ^4.3.0 in toolkit-lib. Older 4.x versions of AdaptiveRetryStrategy only read `rateLimiter` from their options, so adaptive mode would silently drop our max attempts and capped backoff. The lockfile is deduplicated, so the bundled CLI moves from 4.5.5 to 4.6.2. Clarify that a retry strategy must not be shared across services; the two STS clients keep sharing one.
Point the comment at the change that added the `maxAttempts` and `backoff` options to AdaptiveRetryStrategy (smithy-typescript#1922) and at the 4.3.0 changelog entry that shipped it. This corrects the previous commit, which said older versions also drop our max attempts: they accept it as the first constructor argument, and only the options object is ignored.
Raise the minimum in smithyDep() instead of overriding only @smithy/util-retry, and move the explanation and links onto smithyDep(). This supersedes the util-retry-only override from the previous commits. Without a raised minimum, consumers who upgrade toolkit-lib keep whatever @smithy/util-retry their lockfile already has, as long as it satisfies the range. Versions before 4.3.0 ignore the options we pass to AdaptiveRetryStrategy. Re-resolving the range moves the bundled Smithy packages to their latest 4.x releases.
…per's AWS settings Keep one retry test per branch or deliberate decision in our code, and drop the ones that only exercise parseInt/Number edge cases, the SDK, or code that doesn't exist (credentials-file lookup, default-profile fallback). Add a withEnv() helper that sets or unsets the given variables and restores only those, and use it instead of hand-written save/restore code. Use bockfs for test config files, as the other aws-auth tests do. Unset AWS_MAX_ATTEMPTS and AWS_RETRY_MODE and point AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE at /dev/null in the toolkit-lib and aws-cdk Jest setup. Every test that builds an SdkProvider now validates retry settings, so an invalid value in the developer's shell or ~/.aws/config failed unrelated tests.
… base credentials Retry settings are not credentials. Move them out of SdkBaseConfig and add an optional SdkConfig.retry, next to httpOptions, for Toolkit users to set explicitly. Like the proxy settings, the Toolkit doesn't read them from the environment; it validates what it is given when it's constructed. This supersedes SdkBaseConfig.retry from earlier commits, which was never released. The CLI keeps honouring AWS_MAX_ATTEMPTS, AWS_RETRY_MODE and the --profile config: SdkProvider.withAwsCliCompatibleDefaults now reads them itself instead of through AwsCliCompatible.baseConfig(). Also reuse resolveProfile() for the CA bundle lookup in proxy-agent, and drop a test that only guarded an intermediate version of this branch.
…back retrySettingsFromConfig() takes a required profile, so there is no fallback to state.
The @default annotation already says the toolkit's defaults apply.
Values below 1 are rejected, so only 1 disables retries. The old wording, 'values below 2 disable retries', predates the validation.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF ScorecardScorecard details
Scanned Files
|
There was a problem hiding this comment.
See the review summary comment for the overview; the notes below are inline.
| })); | ||
|
|
||
| test('rejects an invalid max attempts', () => withEnv(async () => { | ||
| await expect(retrySettings('default')).rejects.toThrow("invalid value provided for max attempts: 'lots', must be a whole number of at least 1"); | ||
| }, { AWS_MAX_ATTEMPTS: 'lots' })); | ||
|
|
||
| test('rejects an invalid retry mode', () => withEnv(async () => { | ||
| await expect(retrySettings('default')).rejects.toThrow( | ||
| "invalid value provided for retry mode: 'adaptve', must be one of 'standard' or 'adaptive'", | ||
| ); | ||
| }, { AWS_RETRY_MODE: 'adaptve' })); | ||
| }); |
There was a problem hiding this comment.
🟡 Recommended — The PR description says two strict behaviours are deliberate: legacy is rejected, and an empty environment variable overrides the profile and is then rejected. Neither has a test. The retrySettings tests only cover profile reading, env precedence, 'lots' and 'adaptve', and nothing covers max_attempts = 0 in the profile. The commit history shows the legacy handling reversed more than once, and both behaviours decide whether any CLI command runs (AGENTS.md#testing).
Suggested change: Once the legacy and empty-value behaviour is settled, add retrySettings tests with the existing withEnv and configFile helpers: one for AWS_RETRY_MODE: 'legacy', and one for AWS_MAX_ATTEMPTS: '' with configFile('[profile ci]\nmax_attempts = 4\n'). Each should assert the chosen outcome: it either rejects, or resolves to standard or to the profile value.
There was a problem hiding this comment.
Settled on rejecting legacy and treating an empty variable as unset. Added retrySettings tests for both, plus one for max_attempts = 0 in the profile
rix0rrr
left a comment
There was a problem hiding this comment.
Provisionally approved but spare a thought for unnecessary cleverness and have a look at what the AI reviewer is saying
An empty `AWS_MAX_ATTEMPTS=` or `AWS_RETRY_MODE=` now falls back to the profile value, like the JavaScript SDK, instead of overriding it and failing validation. CI templates often pass unset variables through this way. This differs from the AWS CLI v2, which treats an empty variable as set. Adds `retrySettings` tests for empty variables, for rejecting `legacy` (as the AWS CLI v2 does), and for validating values from the profile.
The CLI passes its own retry strategy to every AWS SDK client, which makes the SDK ignore the user's retry configuration. The CLI now honors the standard AWS retry settings, and falls back to its own defaults when they aren't set.
Additions
The CLI reads the standard retry settings
The CLI reads
AWS_MAX_ATTEMPTSandAWS_RETRY_MODE, andmax_attemptsandretry_modefrom the active profile in~/.aws/config(the one selected by--profileorAWS_PROFILE). An environment variable takes precedence over the profile. The settings apply to every SDK client the CLI creates, and the CLI's own capped backoff between attempts is kept.SdkConfig.retryin toolkit-libA new
SdkConfig.retryoption (maxAttempts,mode) configures retries programmatically. LikehttpOptions, it is not read from the environment.Behavioural changes
Because the CLI now respects the standard retry configuration, customers who already have it configured, for example for the AWS CLI, will see these changes when running
cdk.A configured max attempts replaces the CLI's per-client defaults
The defaults are 7 attempts for CloudFormation and most clients, and 3 for STS. A configured value replaces them, including lowering them. For example,
AWS_MAX_ATTEMPTS=1, sometimes set in CI for the AWS CLI, now turns off retries for the CDK too.Invalid values fail every command
Invalid values used to be ignored. They now fail every command, as they do in the AWS CLI v2:
standardoradaptive, solegacyis rejected,Other changes
Each SDK client gets its own retry quota
Every retry strategy has a retry quota: retries spend tokens, and successes refill them. Once the quota is empty, a failed request fails without retrying. Previously, all clients of an SDK instance (except CloudFormation and STS, which have their own) shared one strategy instance, and so one quota. Sustained failures on one service, such as S3 throttling during asset publishing, could empty it and stop retries for healthy services such as ECR and SSM. That takes dozens of failed retries, so in practice it has probably never caused anything serious. Still, each client now has its own quota, which is the correct behaviour and what the SDK does without an explicit strategy. This also keeps adaptive mode's client-side rate limiter per client.
STS backoff is now capped
STS used an uncapped exponential backoff, which was harmless with its fixed 3 attempts. A configured max attempts now applies to STS too, so a large value could make credential checks wait for minutes. STS now uses the same capped backoff as the other clients.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license