Last active
October 3, 2019 05:28
-
-
Save aaronpeterson/00a74bd021a2ae9e3e46596599da4ab0 to your computer and use it in GitHub Desktop.
AWS node.js recursion for 503 SlowDown handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An improvement to this would be linear or eponential increase of wait ms | |
* with a threshold to give up... | |
* | |
*/ | |
async function getTaggings(bucket, key, wait) { | |
let params = { | |
Bucket: bucket, | |
Key: key | |
}; | |
if (wait) | |
await sleep(1000); | |
return new Promise((resolve, reject) => { | |
s3.getObjectTagging(params, function(err, data) { | |
if (err) { | |
if (err.code == "SlowDown") | |
return getTaggings(bucket, key, true); | |
return reject(err); | |
} | |
if (!data.TagSet) | |
return resolve({}); | |
let TagSet = data.TagSet; | |
resolve(TagSet.reduce((acc, e) => { | |
acc[e.Key] = e.Value; | |
return acc; | |
}, {})) | |
}); | |
}); | |
} | |
async function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment