KafkaDlq

class aws_cdk.aws_lambda_event_sources.KafkaDlq(topic_name)

Bases: object

A Kafka topic dead letter queue destination configuration for a Lambda event source.

This destination can only be used with Kafka-based event sources (MSK and self-managed Kafka). When used with other event source types, a validation error will be thrown.

Kafka URI Format

new KafkaDlq(‘my-topic’);

Topic Naming Requirements

Kafka topic names must follow these rules:

  • Only alphanumeric characters, dots (.), underscores (_), and hyphens (-) are allowed

  • Cannot be empty

  • Must be a valid Kafka topic name

ExampleMetadata:

infused

Example:

from aws_cdk.aws_lambda_event_sources import ManagedKafkaEventSource, KafkaDlq

# my_function: lambda.Function


# Your MSK cluster arn
cluster_arn = "arn:aws:kafka:us-east-1:0123456789019:cluster/SalesCluster/abcd1234-abcd-cafe-abab-9876543210ab-4"

# The Kafka topic you want to subscribe to
topic = "some-cool-topic"

# Create a Kafka DLQ destination
kafka_dlq = KafkaDlq("failure-topic")

my_function.add_event_source(ManagedKafkaEventSource(
    cluster_arn=cluster_arn,
    topic=topic,
    starting_position=lambda_.StartingPosition.TRIM_HORIZON,
    on_failure=kafka_dlq,
    provisioned_poller_config=ProvisionedPollerConfig(
        minimum_pollers=1,
        maximum_pollers=1
    )
))

Creates a new Kafka DLQ destination.

Parameters:

topic_name (str)

Throws:

{TypeError} When the topic name is empty or contains invalid characters

Methods

bind(_target, _target_handler)

Returns a destination configuration for the DLQ.

The returned configuration is used in the AWS Lambda EventSourceMapping’s DestinationConfig to specify where failed records should be sent.

Parameters:
Return type:

DlqDestinationConfig

Returns:

The DLQ destination configuration with the properly formatted Kafka URI