如何使用 lambda 触发器检测 DynamoDB 中的 PutItem 操作?
How to detect PutItem operation in DynamoDB using lambda trigger?
我在 AWS Lambda
中有一个函数,它由 AWS DynamoDB
中的操作触发。该函数包含此代码,假设使用 AWS SNS
:
发送新的推送消息
console.log('Loading function');
var AWS = require('aws-sdk');
AWS.config.region = 'us-west-2';
exports.handler = function(event, context) {
console.log("\n\nLoading handler\n\n");
var sns = new AWS.SNS();
sns.publish({
Message: 'Test publish to SNS from Lambda',
TopicArn: 'TOPIC_ARN'
}, function(err, data) {
if (err) {
console.log(err.stack);
return;
}
console.log('push sent');
console.log(data);
context.done(null, 'Function Finished!');
});
};
如何仅在 DynamoDB
table 中发生 PutItem
操作时触发此 Lambda
代码?
此外,有没有办法将新添加的项目的属性获取到 table 并检查其中一个是否等于字符串?
This 是我在 AWS 开发人员论坛上的问题。
// Check if it is PutItem event
if (record.eventName == "INSERT") {
...
// Get item's id
var id = record.dynamodb.Keys.Id.N;
...
}
我在 AWS Lambda
中有一个函数,它由 AWS DynamoDB
中的操作触发。该函数包含此代码,假设使用 AWS SNS
:
console.log('Loading function');
var AWS = require('aws-sdk');
AWS.config.region = 'us-west-2';
exports.handler = function(event, context) {
console.log("\n\nLoading handler\n\n");
var sns = new AWS.SNS();
sns.publish({
Message: 'Test publish to SNS from Lambda',
TopicArn: 'TOPIC_ARN'
}, function(err, data) {
if (err) {
console.log(err.stack);
return;
}
console.log('push sent');
console.log(data);
context.done(null, 'Function Finished!');
});
};
如何仅在 DynamoDB
table 中发生 PutItem
操作时触发此 Lambda
代码?
此外,有没有办法将新添加的项目的属性获取到 table 并检查其中一个是否等于字符串?
This 是我在 AWS 开发人员论坛上的问题。
// Check if it is PutItem event
if (record.eventName == "INSERT") {
...
// Get item's id
var id = record.dynamodb.Keys.Id.N;
...
}