I am using @aws-sdk/client-iam
SDK from AWS for JavaScript, In a node based server. We are using GetGroupCommand
.
If we aggressivley call above command AWS SDK throws Throttling
error, with a field error?.$metadata?.totalRetryDelay
which tells after how many milliseconds we shall retry the request.
Based on this trial - error thing we have modified the calls to sleep for certain amount of time, But when calls are too many they all retry after sleep causing the AWS server to flood again & throw the Throttling
error.
I couldn't find any guide/reference for AWS JS IAM SDK 3 explaining under what conditions it may throw Throttling
error.
There is middleware https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_middleware_retry.html I guess it's something we can use, but not sure how. Sample example of this or best practices for throttling
for AWS SDK JS 3 are not mentioned on the github repo or the sdk guide.
Can you show me how to handle this Throttling
issue in AWS SDK 3 for JS?
None of the following have any helpful information about throttling,
SDK Reference: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html
Developer guide: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html
Code examples: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sdk-code-samples.html
That totalRetryDelay
value would be most useful to you if your nodejs program were not sending multiple concurrent requests to the API. It tells you how long to wait before you send one more request, not 10 or 50 more.
The solution to your problem might be to put your requests into some sort of internal queue and send them one at a time with a short delay between them.
Or, if you know how many concurrent requests you send, you could try multiplying totalRetryDelay
by that number and delay that much.