使用 Lambda 设置 DynamoDB 触发器

2023-06-26Java开发问题
23

本文介绍了使用 Lambda 设置 DynamoDB 触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 DynamoDB Streams 和 AWS Lambda 创建一个 DynamoDB 触发器.我进行了很多研究,但找不到任何方法来读取和处理 Java 8 中的 DynamoDB Stream 事件.我对这两种技术都是全新的,所以不知道如何使用它.

I'm trying to create a DynamoDB trigger using DynamoDB Streams and AWS Lambda. I researched a lot but I couldn't find any way to read and process a DynamoDB Stream event in Java 8. I'm completely new to both these technologies so don't know how to work with this.

本质上,我想做的是每当在表 A 中创建记录时在表 B 中创建记录.

Essentially, what I want to do is create a record in table B whenever a record is created in table A.

谁能给我指出一个用Java处理这个用例的代码或帖子?

Could any of you please point me to a code or post that handles this use case in Java?

谢谢:)

推荐答案

这段代码对我有用.您可以使用它在 Lambda 函数中接收和处理 DynamoDB 事件 -

This code worked for me. You can use it to receive and process DynamoDB events in a Lambda function -

public class Handler implements RequestHandler<DynamodbEvent, Void> {

    @Override
    public Void handleRequest(DynamodbEvent dynamodbEvent, Context context) {

        for (DynamodbStreamRecord record : dynamodbEvent.getRecords()) {

            if (record == null) {
                continue;
            }

            // Your code here
            // Write to Table B using DynamoDB Java API
        }

        return null;
    }
}

创建 Lambda 时,将表 A 中的流添加为事件源,一切顺利

When you create your Lambda, add the stream from table A as your event source, and you're good to go

这篇关于使用 Lambda 设置 DynamoDB 触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13