我正在 Node 中使用以下 Javascript 删除 DynamoDB 中的表。
var params = {
TableName : "MyTable"
};
dynamodb.deleteTable(params, function(err, data) {
// Not really done yet...!
});
我需要知道表何时被实际删除。回调并不表明这一点,因为调用它时它仍然处于删除过程中。有没有办法知道删除何时完成?
最佳答案
waitFor
API可用于检查表是否不存在。
Waits for the tableNotExists state by periodically calling the underlying DynamoDB.describeTable() operation every 20 seconds (at most 25 times).
使用 waitFor API 删除表并检查表是否不存在的示例代码:-
var AWS = require("aws-sdk");
AWS.config.update({
region : "us-west-2",
endpoint : "http://localhost:8000"
});
var dynamodb = new AWS.DynamoDB();
var params = {
TableName : "country"
};
var paramsWaitFor = {
TableName : 'country' /* required */
};
function waitForTableNotExists() {
dynamodb.waitFor('tableNotExists', paramsWaitFor, function(waitForErr,
waitForData) {
if (waitForErr) {
console.log(waitForErr, waitForErr.stack); // an error occurred
} else {
console.log('Deleted ====>', JSON.stringify(waitForData, null, 2));
}
});
}
dynamodb.deleteTable(params, function(err, data) {
if (err) {
console.error("Unable to delete table. Error JSON:", JSON.stringify(
err, null, 2));
} else {
console.log("Deleted table. Table description JSON:", JSON.stringify(
data, null, 2));
waitForTableNotExists();
}
});
关于amazon-web-services - DynamoDB 删除表完成状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40669415/