删除并创建 dynamoDB table
Delete and create dynamoDB table
使用 node.js 我尝试再次删除和创建 dynamoDB table。我需要从 table 中删除所有记录并添加新记录,所以我认为删除并重新创建整个 table 是一个很好的解决方案。我尝试使用此代码
dynamo.deleteTable({
TableName: tableName
}, function(err, data){
if (err) {
console.log(err);
}
else {
dynamo.createTable({
TableName: tableName,
KeySchema: [{
AttributeName: "id",
KeyType: "HASH"
}],
AttributeDefinitions: [{
AttributeName: "id",
AttributeType: "S"
}],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}, function(err){
if (err) {
console.log(err);
}
else {
// putNewData(data, callback);
}
})
}
});
我收到错误 ResourceInUseException:Table 已经存在:
DynamoDB 实际删除 table 需要一些时间,因此您需要等到 table 被删除。
如果出现 ResourceInUseException 错误,则表示您尝试重新创建的 table 尚未删除。所以您需要稍等片刻,然后重试。
如果您不更改 table 中的键,并且不创建新的本地二级索引,则可以改用 UpdateTable 方法。不过这里有一些限制:
You can only perform one of the following operations at once:
Modify the provisioned throughput settings of the table.
Enable or disable Streams on the table.
Remove a global secondary index from the table.
Create a new global secondary index on the table. Once the index
begins
backfilling, you can use UpdateTable to perform other operations.
您可以使用 SDK 的 tableNotExists
waiter 来确保 table 在调用 createTable
之前已被完全删除。
使用 node.js 我尝试再次删除和创建 dynamoDB table。我需要从 table 中删除所有记录并添加新记录,所以我认为删除并重新创建整个 table 是一个很好的解决方案。我尝试使用此代码
dynamo.deleteTable({
TableName: tableName
}, function(err, data){
if (err) {
console.log(err);
}
else {
dynamo.createTable({
TableName: tableName,
KeySchema: [{
AttributeName: "id",
KeyType: "HASH"
}],
AttributeDefinitions: [{
AttributeName: "id",
AttributeType: "S"
}],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}, function(err){
if (err) {
console.log(err);
}
else {
// putNewData(data, callback);
}
})
}
});
我收到错误 ResourceInUseException:Table 已经存在:
DynamoDB 实际删除 table 需要一些时间,因此您需要等到 table 被删除。
如果出现 ResourceInUseException 错误,则表示您尝试重新创建的 table 尚未删除。所以您需要稍等片刻,然后重试。
如果您不更改 table 中的键,并且不创建新的本地二级索引,则可以改用 UpdateTable 方法。不过这里有一些限制:
You can only perform one of the following operations at once:
Modify the provisioned throughput settings of the table.
Enable or disable Streams on the table.
Remove a global secondary index from the table.
Create a new global secondary index on the table. Once the index begins
backfilling, you can use UpdateTable to perform other operations.
您可以使用 SDK 的 tableNotExists
waiter 来确保 table 在调用 createTable
之前已被完全删除。