All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.funqy.lambda.event.dynamodb.PipesDynamoDbEventHandler Maven / Gradle / Ivy

The newest version!
package io.quarkus.funqy.lambda.event.dynamodb;

import java.io.InputStream;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord;
import com.amazonaws.services.lambda.runtime.events.StreamsEventResponse;

import io.quarkus.funqy.lambda.config.FunqyAmazonConfig;
import io.quarkus.funqy.lambda.event.EventHandler;

public class PipesDynamoDbEventHandler
        implements EventHandler, DynamodbStreamRecord, StreamsEventResponse> {

    @Override
    public Stream streamEvent(List event, FunqyAmazonConfig amazonConfig) {
        if (event == null) {
            return Stream.empty();
        }
        return event.stream();
    }

    @Override
    public String getIdentifier(DynamodbStreamRecord message, FunqyAmazonConfig amazonConfig) {
        return message.getDynamodb().getSequenceNumber();
    }

    @Override
    public Supplier getBody(DynamodbStreamRecord message, FunqyAmazonConfig amazonConfig) {
        throw new IllegalStateException("""
                DynamoDB records are too specific. It is not supported to extract a message from them. \
                Use the DynamodbStreamRecord in your funq method, or use EventBridge Pipes with CloudEvents.
                """);
    }

    @Override
    public StreamsEventResponse createResponse(List failures, FunqyAmazonConfig amazonConfig) {
        if (!amazonConfig.advancedEventHandling().dynamoDb().reportBatchItemFailures()) {
            return null;
        }
        return StreamsEventResponse.builder().withBatchItemFailures(
                failures.stream().map(id -> StreamsEventResponse.BatchItemFailure.builder()
                        .withItemIdentifier(id).build()).toList())
                .build();
    }

    @Override
    public Class getMessageClass() {
        return DynamodbStreamRecord.class;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy