问题描述
我正在尝试使用 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 触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!