ManagedKafkaEventSourceProps

class aws_cdk.aws_lambda_event_sources.ManagedKafkaEventSourceProps(*, starting_position, batch_size=None, enabled=None, max_batching_window=None, topic, secret=None, cluster_arn)

Bases: aws_cdk.aws_lambda_event_sources.KafkaEventSourceProps

Properties for a MSK event source.

Parameters
  • starting_position (StartingPosition) – Where to begin consuming the stream.

  • batch_size (Union[int, float, None]) – The largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function. Your function receives an event with all the retrieved records. Valid Range: - Minimum value of 1 - Maximum value of: - 1000 for {@link DynamoEventSource} - 10000 for {@link KinesisEventSource}, {@link ManagedKafkaEventSource} and {@link SelfManagedKafkaEventSource} Default: 100

  • enabled (Optional[bool]) – If the stream event source mapping should be enabled. Default: true

  • max_batching_window (Optional[Duration]) – The maximum amount of time to gather records before invoking the function. Maximum of Duration.minutes(5) Default: Duration.seconds(0)

  • topic (str) – The Kafka topic to subscribe to.

  • secret (Optional[ISecret]) – The secret with the Kafka credentials, see https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html for details This field is required if your Kafka brokers are accessed over the Internet. Default: none

  • cluster_arn (str) – An MSK cluster construct.

ExampleMetadata

infused

Example:

from aws_cdk.aws_secretsmanager import Secret
from aws_cdk.aws_lambda_event_sources import ManagedKafkaEventSource

# 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"

# The secret that allows access to your MSK cluster
# You still have to make sure that it is associated with your cluster as described in the documentation
secret = Secret(self, "Secret", secret_name="AmazonMSK_KafkaSecret")
my_function.add_event_source(ManagedKafkaEventSource(
    cluster_arn=cluster_arn,
    topic=topic,
    secret=secret,
    batch_size=100,  # default
    starting_position=lambda_.StartingPosition.TRIM_HORIZON
))

Attributes

batch_size

The largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.

Your function receives an event with all the retrieved records.

Valid Range:

  • Minimum value of 1

  • Maximum value of:

    • 1000 for {@link DynamoEventSource}

    • 10000 for {@link KinesisEventSource}, {@link ManagedKafkaEventSource} and {@link SelfManagedKafkaEventSource}

Default

100

Return type

Union[int, float, None]

cluster_arn

An MSK cluster construct.

Return type

str

enabled

If the stream event source mapping should be enabled.

Default

true

Return type

Optional[bool]

max_batching_window

The maximum amount of time to gather records before invoking the function.

Maximum of Duration.minutes(5)

Default

Duration.seconds(0)

Return type

Optional[Duration]

secret

//docs.aws.amazon.com/msk/latest/developerguide/msk-password.html for details This field is required if your Kafka brokers are accessed over the Internet.

Default

none

Type

The secret with the Kafka credentials, see https

Return type

Optional[ISecret]

starting_position

Where to begin consuming the stream.

Return type

StartingPosition

topic

The Kafka topic to subscribe to.

Return type

str