node.js - 从 LAMBDA 触发器更新 DynanoDB
问题描述
每当表上发生事件时,我试图使用带有一些值的 lambda 触发器更新我MODIFY
的表,但即使触发了该函数,更新查询也不会运行,并且更改不会反映在 dynamodb 中,并且CloudWatch
没有显示有关的错误日志更新我已经为我的 Lambda 提供了AmazonDynamoDBFullAccess
和AWSLambdaDynamoDBExecutionRole
权限。代码不适用于更新。
var AWS = require('aws-sdk');
// extra
const docClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async (event , context , callback) => {
// TODO implement
event.Records.forEach((record) => {
console.log('Stream record: ', JSON.stringify(record, null, 2));
// logic to find insert type / modify type
//if(record.eventName == 'MODIFY' || record.eventName == 'INSERT'){
if(record.eventName == 'MODIFY'){
// extract student id, and marks from event itself (save I/O)
console.log("Printing new image values",JSON.stringify(record.dynamodb.NewImage,null,2));
// modify the same record once new value is calculated
//############# code for pushing to DynamoDB #################
var params = {
TableName:'my-table name',
Key:{
"student_id": 'abc_123'
},
UpdateExpression: "set score1 = :r",
ExpressionAttributeValues:{
":r":88
},
ReturnValues:"UPDATED_NEW"
};
console.log("Updating the item...");
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
}
});
//############# end of code ###############
}
});
console.log(event);
const response = {
statusCode: 200,
body: JSON.stringify(event),
};
return response;
};
我哪里错了?
谢谢您的帮助 !!
解决方案
推荐阅读
- django - uwsgi pidfile 被自动删除
- c# - 将 wpf 数据网格滚动到特定行并聚焦该行
- batch-file - 批处理文件中的输出符号“>>”
- postgresql - 如何在 postgresql 模式中查找特定表的数据长度和索引长度?
- javascript - Angular 7隐藏ngFor循环内的特定属性
- python-3.x - 将 python 2 代码更新为 googleads api 的 python 3 代码
- ios - 苹果应用内购买服务器回调 JSON 不包含“latest_receipt_info”键?
- wordpress - 找不到重定向“配置文件”
- javascript - 如何从输入标签中的单个选择选项中显示每个选定的值
- flutter - 带有圆形图像图标的颤振布局