2016-11-18 46 views
1

我正在Node中使用以下Javascript刪除DynamoDB中的表。DynamoDB刪除表完成狀態

var params = { 
    TableName : "MyTable" 
}; 

dynamodb.deleteTable(params, function(err, data) { 
    // Not really done yet...! 
}); 

我需要知道表何時被刪除。回調並不表示這一點,因爲當它被調用時它仍處於刪除過程中。有沒有辦法知道刪除何時完成?

回答

2

waitFor API可用於檢查表的不存在。

等待通過週期性地調用 底層DynamoDB.describeTable()操作,每20秒( 至多25倍)tableNotExists狀態。

示例代碼刪除表,並檢查使用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(); 

    } 
}); 
+0

哇,救了我的構建服務器的脖子。謝謝。 –