Skip to content
v2.274.0

ManagedKafkaEventSource Class ​

Use a MSK cluster as a streaming source for AWS Lambda.

Example ​

ts
import { ManagedKafkaEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
import { StartingPosition, Function } from 'aws-cdk-lib/aws-lambda';

// With provisioned pollers and poller group for cost optimization
declare const myFunction: Function;
myFunction.addEventSource(new ManagedKafkaEventSource({
  clusterArn: 'arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-abcd-cafe-abab-9876543210ab-4',
  topic: 'orders-topic',
  startingPosition: StartingPosition.LATEST,
  provisionedPollerConfig: {
    minimumPollers: 2,
    maximumPollers: 10,
    pollerGroupName: 'shared-kafka-pollers',
  },
}));
python
from aws_cdk.aws_lambda_event_sources import ProvisionedPollerConfig
from aws_cdk.aws_lambda_event_sources import ManagedKafkaEventSource
from aws_cdk.aws_lambda import StartingPosition, Function

# With provisioned pollers and poller group for cost optimization
# my_function: Function

my_function.add_event_source(ManagedKafkaEventSource(
    cluster_arn="arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-abcd-cafe-abab-9876543210ab-4",
    topic="orders-topic",
    starting_position=StartingPosition.LATEST,
    provisioned_poller_config=ProvisionedPollerConfig(
        minimum_pollers=2,
        maximum_pollers=10,
        poller_group_name="shared-kafka-pollers"
    )
))
java
import software.amazon.awscdk.services.lambda.eventsources.ManagedKafkaEventSource;
import software.amazon.awscdk.services.lambda.StartingPosition;
import software.amazon.awscdk.services.lambda.Function;

// With provisioned pollers and poller group for cost optimization
Function myFunction;

myFunction.addEventSource(ManagedKafkaEventSource.Builder.create()
        .clusterArn("arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-abcd-cafe-abab-9876543210ab-4")
        .topic("orders-topic")
        .startingPosition(StartingPosition.LATEST)
        .provisionedPollerConfig(ProvisionedPollerConfig.builder()
                .minimumPollers(2)
                .maximumPollers(10)
                .pollerGroupName("shared-kafka-pollers")
                .build())
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda.EventSources;
using Amazon.CDK.AWS.Lambda;

// With provisioned pollers and poller group for cost optimization
Function myFunction;

myFunction.AddEventSource(new ManagedKafkaEventSource(new ManagedKafkaEventSourceProps {
    ClusterArn = "arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-abcd-cafe-abab-9876543210ab-4",
    Topic = "orders-topic",
    StartingPosition = StartingPosition.LATEST,
    ProvisionedPollerConfig = new ProvisionedPollerConfig {
        MinimumPollers = 2,
        MaximumPollers = 10,
        PollerGroupName = "shared-kafka-pollers"
    }
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

// With provisioned pollers and poller group for cost optimization
var myFunction Function

myFunction.AddEventSource(awscdk.NewManagedKafkaEventSource(&ManagedKafkaEventSourceProps{
	ClusterArn: jsii.String("arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-abcd-cafe-abab-9876543210ab-4"),
	Topic: jsii.String("orders-topic"),
	StartingPosition: awscdk.StartingPosition_LATEST,
	ProvisionedPollerConfig: &ProvisionedPollerConfig{
		MinimumPollers: jsii.Number(2),
		MaximumPollers: jsii.Number(10),
		PollerGroupName: jsii.String("shared-kafka-pollers"),
	},
}))

Initializer ​

ts
new ManagedKafkaEventSource(props: ManagedKafkaEventSourceProps)
python
ManagedKafkaEventSource(props: ManagedKafkaEventSourceProps)
java
new ManagedKafkaEventSource(ManagedKafkaEventSourceProps props)
csharp
new ManagedKafkaEventSource(ManagedKafkaEventSourceProps props)
go
NewManagedKafkaEventSource(Props ManagedKafkaEventSourceProps)

Properties ​

eventSourceMappingArnstringevent_source_mapping_arnstreventSourceMappingArnStringEventSourceMappingArnstringEventSourceMappingArn*stringrequired#
The ARN for this EventSourceMapping.
eventSourceMappingIdstringevent_source_mapping_idstreventSourceMappingIdStringEventSourceMappingIdstringEventSourceMappingId*stringrequired#
The identifier for this EventSourceMapping.

Methods ​

bind(target: IFunction): voiddef bind(self, target: IFunction) -> Nonepublic void bind(IFunction target)public void Bind(IFunction target)func Bind(Target IFunction)#
Called by `lambda.addEventSource` to allow the event source to bind to this function.