public static < T > T performAmazonActionWithRetry ( String actionLabel , Supplier < T > action , int retryLimit , int durationInMillis ) { int retryCount = 0 ; do { try { return action . get ( ) ; } catch ( LimitExceededException | ProvisionedThroughputExceededException | KMSThrottlingException e ) { // We should just wait a little time before trying again int remainingRetries = retryLimit - retryCount ; LOG . debug ( "Amazon exception caught" , args -> args . add ( "exception" , e . getClass ( ) . getName ( ) ) . add ( "action" , actionLabel ) . add ( "remainingRetryCount" , remainingRetries ) ) ; } sleepUntilInterrupted ( actionLabel , durationInMillis ) ; } while ( retryCount ++ < retryLimit ) ; throw new AwsException ( "Limit exceeded, all retries failed" , args -> args . add ( "action" , actionLabel ) . add ( "retryLimit" , retryLimit ) ) ; }
Handle retry for amazon quotas