Last active
March 31, 2020 23:00
-
-
Save tommedema/13b5840ac3b1003178dfab8a0aa6bc6d to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Note that this temporarily works around an issue where Amplify does not support | |
* the AWS SDK' correctClockSkew option, by retrying with a manually defined offset | |
* if the request time is too skewed. | |
* @see https://github.com/aws-amplify/amplify-js/issues/2014 | |
*/ | |
const attemptPutWithClockSkewRetry = () => | |
Storage | |
.put( | |
itemKey, | |
itemData | |
) | |
.catch(async err => { | |
if (err.code === 'RequestTimeTooSkewed') { | |
const serverTimeFetch = await fetch('https://your-lambda-function-returning-server-time.amazonaws.com/time', { headers: { "Accept": "application/json" } }) | |
const serverTimeFetchResponse = await serverTimeFetch.json() | |
const systemClockOffset = serverTimeFetchResponse.time - Date.now() | |
console.log(`setting systemClockOffset to %s`, systemClockOffset) | |
AWS.config.update({ | |
systemClockOffset | |
}) | |
if (!err.retryable) { | |
attemptPutWithClockSkewRetry() | |
} | |
} | |
else { | |
throw err | |
} | |
}) | |
attemptPutWithClockSkewRetry() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment