我正试图找到一种正确的方法来刷新我从科尼图获得的AWS.config.credentials。我使用的是开发人员授权的身份,它可以正常工作。我获得凭据,如果我执行refresh(),AWS.config.credentials.expireTime也会按预期更新。
凭证在一个小时后过期,所以我想我可以使用setTimeout刷新凭据并根据credentials.expireTime配置它(我计算了millis的数量)。
但是,我似乎不得不更频繁地执行刷新操作。凭据总是在他们的时间之前超时。如果我将延迟减少到更小的数量,则setTimeout-方法工作得很好,但我希望不要过度执行刷新。
这是真的吗?如果是的话,我需要多久这样做一次?让它每5分钟刷新一次似乎太过了:/
循环刷新
function refreshAwsCredentials() {
clearTimeout(awsRenewalTimeout);
// perform credentials renewal
AwsService.refreshAwsCredentials()
.then( function () {
awsRenewalTimeout = setInterval(
function () {
refreshAwsCredentials();
}, AWS.config.credentials.expireTime.getTime() - new Date().getTime() - 300000
);
})
.catch( function (error) {
// checks error, normally it basically logs in, then refreshes
});
}AwsService.refreshAwsCredentials()
if ( AWS.config.credentials.needsRefresh() ) {
AWS.config.credentials.refresh( function (error) {
if (error) {
// rejects promise with error message
}
else {
// resolves promise
}
});
}发布于 2016-05-20 12:15:16
最后,我发现在我过于具体的地方,我对错误进行了检查。我检查了是否已登录,而不是凭据是否超时。现在,当事情失败时,我尝试登录,并且在需要时凭据超时现在被解决了。
https://stackoverflow.com/questions/37179906
复制相似问题