[英]DynamoDB Streams - Querying and Batch Delete
我有两张桌子:
JobListings
JobListingImages
英文说明:当我删除一个职位列表时,我希望JobListingImages
表中与该职位列表关联的所有图像也被删除。
代码说明:当 JobListings 中发生JobListings
streamedItem.eventName === "REMOVE"
事件时,我想查询JobListingImages
中的JobListingID
属性,返回所有记录,然后删除。
我的用例分步骤:
streamedItem.eventName === "REMOVE"
触发器 Lambda function到目前为止,这是我的工作:
exports.handler = async (event) => {
for (const streamedItem of event.Records) {
if (streamedItem.eventName === "REMOVE") {
//Get the ID of the deleted draft job listing
const id = streamedItem.dynamodb.OldImage.id.S;
let imagesToDelete = [];
//Organise the parameters to query JobListingImages table
var params = {
TableName: table,
FilterExpression: "#draftJobListingID = :draftJobListingID",
ExpressionAttributeNames: {
"#draftJobListingID": "draftJobListingID",
},
ExpressionAttributeValues: {
":draftJobListingID": id,
},
Select: "SPECIFIC_ATTRIBUTES",
AttributesToGet: [id],
};
//Query the table, and store the results
documentClient
.query(params, function (err, data) {
if (err) console.log("THERE WAS AN ERROR", err);
else {
imagesToDelete = data
}
})
.promise();
// Batch delete all the stored items
//...Code here (unsure how to complete)
return { status: "done" };
}
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.