New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added awsRequest for aws-sdk call backoff and retry in customResources #8338
Changes from 3 commits
a025816
49b9f15
cbafc9c
8f0b61d
2c43a32
53d52aa
0a0725b
d2afc2c
8a4523b
ff2a285
3d1a697
ae40f38
5875539
803324d
646043c
ea0863f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,11 +90,40 @@ function wait(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
const MAX_AWS_REQUEST_TRY = (() => { | ||
const DEFAULT_MAX_AWS_REQUEST_TRY = 4; | ||
const userValue = Number(process.env.SLS_AWS_REQUEST_MAX_RETRIES); | ||
return userValue >= 0 ? userValue : DEFAULT_MAX_AWS_REQUEST_TRY; | ||
})(); | ||
|
||
function awsRequest(serviceInstance, method, ...args) { | ||
const callAws = requestTry => { | ||
return serviceInstance[method](...args) | ||
.promise() | ||
.then( | ||
result => result, | ||
error => { | ||
if ( | ||
requestTry < MAX_AWS_REQUEST_TRY && | ||
error && | ||
(error.statusCode === 429 || | ||
(error.retryable && error.statusCode !== 403 && error.code !== 'CredentialsError')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can limit this to |
||
) { | ||
return wait(4000 + Math.random() * 3000).then(() => callAws(++requestTry)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 7 seconds, is a lot in lambda, let's make it maybe |
||
} | ||
throw error; | ||
} | ||
); | ||
}; | ||
return callAws(1); | ||
} | ||
|
||
module.exports = { | ||
logger, | ||
response, | ||
getEnvironment, | ||
getLambdaArn, | ||
handlerWrapper, | ||
wait, | ||
awsRequest, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use async/await