gpt4 book ai didi

amazon-web-services - 如何发送数据触发lambda函数?

转载 作者:行者123 更新时间:2023-12-02 01:08:32 25 4
gpt4 key购买 nike

我想从 DynamoDb 发送更改的数据触发 lambda 函数。然后我想将这个更改的数据保存在不同的 DynamoDb 表中。

编程语言:NodeJs

DynomaDb
启用流:是
查看类型:新旧图片

Lambda 函数

'use strict';

console.log('Loading function');

exports.handler = (event, context, callback) => {
//console.log('Received event:', JSON.stringify(event, null, 2));
event.Records.forEach((record) => {
console.log(record.eventID);
console.log(record.eventName);
console.log('DynamoDB Record: %j', record.dynamodb);
});
callback(null, `Successfully processed ${event.Records.length} records.`);
};

它不工作。

最佳答案

DynamoDB 流和 Lambda 可用于上述用例。

1) 在 Dynamodb 表上启用 DynamoDB 流以流式传输数据

2) 创建一个 Lambda 函数来使用流并写入另一个 DynamoDB 表。可以使用多种编程语言 (API) 创建 Lambda 函数。您可以使用 AWS SDK 创建 lambda 函数。

有关详细信息,请参阅以下链接。

Full documentation

Enable Streams and Lambda - Cross region replication use case

流 View 类型:-

StreamViewType—specifies the information that will be written to the stream whenever data in the table is modified:

KEYS_ONLY—only the key attributes of the modified item.

NEW_IMAGE—the entire item, as it appears after it was modified.

OLD_IMAGE—the entire item, as it appeared before it was modified.

NEW_AND_OLD_IMAGES—both the new and the old images of the item.

事件名称:-

当数据在 DynamoDB 表中更新时,

record.eventName 应该有 MODIFY

record.dynamodb 应具有基于流 View 类型的值。如果您选择了 NEW_AND_OLD_IMAGES,那么它应该同时具有旧值和新值。

eventName — (String) The type of data modification that was performed on the DynamoDB table:

INSERT - a new item was added to the table.

MODIFY - one or more of an existing item's attributes were modified.

REMOVE - the item was deleted from the table

关于amazon-web-services - 如何发送数据触发lambda函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46443529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com