我是一名刚接触 AWS 的学生,但我遇到了障碍...... 我正在尝试使用 lambda 函数来更新我的 dynamodb 表中项目的属性。正在触发 lambda 函数,但由于某种原因我无法更新该项目。
我能够从 dynamodb 中成功删除项目,但是当我尝试更新项目的属性时,没有任何反应。
函数执行后,human_confirmed 属性未更新为 true。我一直在尝试在 Google 上找到的不同东西,但没有任何效果:(
console.log('Loading function');
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
AWS.config.update({
region: "us-east-1"
});
var dynamodb = new AWS.DynamoDB.DocumentClient();
var instance = event.instanceID;
var InstanceName = instance;
var params = {
TableName: "reminders",
Key: {
"instanceID": {
S: InstanceName
},
},
UpdateExpression: 'SET #a = :x',
ExpressionAttributeNames: {'#a' : 'human_confirmed'},
ExpressionAttributeValues: {
':x' : 'true',
},
ReturnValues:"UPDATED_NEW"
};
dynamodb.update(params, function(err, data) {
if (err)
callback(err, null); // an error occurred
else
callback(null, data); // successful response
});
callback(null, "Updating resource from reminder table: " + InstanceName + ".... The system will no longer contain automated emails about this resource's tags!");
};
最佳答案
确保你有这个配置:dynamodb:PutItem
在你的 serverless.yml
文件中
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:PutItem"
Resource: "*"
关于node.js - 用 nodejs 编写的 AWS Lambda 函数没有更新我的 DynamoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56711337/