这可能是由于AWS IOT更新证书机制导致的。在调用updateCertificate函数之前,先调用函数getConfig以获取当前的证书配置,并在updateCertificate函数中使用该配置。此外,使用jQuery的ajaxComplete事件可以避免不必要的多次调用。
代码示例:
var iot = new AWS.Iot();
var certificateId = 'certificateId';
// 获取当前证书的配置
iot.getConfig({thingName: certificateId}, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
var certificateConfig = {
certificateId: certificateId,
newStatus: 'REVOKED_NON_ACTIVE',
currentVersion: data.version
};
// 设置ajaxComplete事件以避免多次调用
$( document ).ajaxComplete(function() {
console.log( "AWS IOT UpdateCertificate has been completed." );
$( this ).unbind( "ajaxComplete" );
});
// 使用当前证书的配置更新证书
iot.updateCertificate(certificateConfig, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
}
});
}
});