我遇到了同样的问题,但我迁移了我的基础,所以我用一个可能对你有帮助的后置脚本解决了这个问题。此外,您可以使用 DMS 事件来通知 SMS,然后调用 lambda 来实现。
使用节点只需运行 file.js init()
const AWS = require("aws-sdk");
AWS.config.update({
region: "us-east-1"
});
const documentClient = new AWS.DynamoDB.DocumentClient();
let invalidList = [];
const TableName = 'TableName';
const params = {
TableName: TableName,
};
module.exports.init = function () {
console.log("Start Conversions of Details Booleans")
documentClient.scan(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Scan succeeded.");
// By default scan retrieves at max 1 mb of data
if (typeof data.LastEvaluatedKey != "undefined") {
console.log("Scanning for more...");
params.ExclusiveStartKey = data.LastEvaluatedKey;
documentClient.scan(params, onScan);
}
invalidList = getinvalidList(data);
if(invalidList.length == 0) {
console.log("All data is aready migrated");
return;
}
updateList(invalidList);
}
});
};
function getinvalidList(list) {
return list.Items.reduce((invalidList, item) => {
if (item) {
const variable = (item.variable && item.variable != undefined) ? item.variable : '0';
if (isNotBoolean(variable)) {
invalidList.push(item);
}
}
return invalidList;
}, []);
}
function updateList(list) {
list.forEach(item => {
var params = {
TableName: TableName,
Key: {
"id": item.id,
},
UpdateExpression: "set variable = :variable",
ExpressionAttributeValues: {
":variable": newValue(item.variable),
},
ReturnValues: "UPDATED_NEW"
};
documentClient.update(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
},
)
});
}
function newValue(variable) {
return isNotBoolean(variable) ? !!+variable : variable
}
function isNotBoolean(variable) {
return (typeof variable !== 'boolean')
}