@@ -20,8 +20,24 @@ export function throttlingBackOff<T>(
2020 request : ( ) => Promise < T > ,
2121 options ?: Partial < Omit < IBackOffOptions , 'retry' > > ,
2222) : Promise < T > {
23+ const defaultDelay = 500 ;
24+ let maxDelayValue = 2000 ;
25+
26+ if ( process . env . BACKOFF_START_DELAY ) {
27+ const backoffStartDelay = parseInt ( process . env . BACKOFF_START_DELAY , 10 ) ;
28+ if ( Number . isInteger ( backoffStartDelay ) ) {
29+ maxDelayValue = backoffStartDelay ;
30+ }
31+ }
32+
33+ // Add jitter to the starting delay
34+ const startingDelay = Math . random ( ) * ( maxDelayValue - defaultDelay + 1 ) + defaultDelay ;
35+
36+ console . log ( `throttlingBackOff delay set to ${ startingDelay } ` ) ;
37+
2338 return backOff ( request , {
24- startingDelay : 500 ,
39+ startingDelay,
40+ delayFirstAttempt : true ,
2541 jitter : 'full' ,
2642 retry : isThrottlingError ,
2743 ...options ,
@@ -34,6 +50,7 @@ export const isThrottlingError = (e: any) =>
3450 e . code === 'ConcurrentModificationException' || // Retry for AWS Organizations
3551 e . code === 'InsufficientDeliveryPolicyException' || // Retry for ConfigService
3652 e . code === 'NoAvailableDeliveryChannelException' || // Retry for ConfigService
53+ e . code === 'ConcurrentModifications' || // Retry for AssociateHostedZone
3754 e . code === 'TooManyRequestsException' ||
3855 e . code === 'Throttling' ||
3956 e . code === 'ThrottlingException' ||
0 commit comments