# ManagedKafkaEventSource

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

Extends: [StreamEventSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.StreamEventSource.html) › ManagedKafkaEventSource
Implements: [IEventSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IEventSource.html)

- Source: [`aws-lambda-event-sources/lib/kafka.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-lambda-event-sources/lib/kafka.ts#L249)
- Type last changed: v2.77.0 · 26 Apr 2023

## Example

TypeScript:

```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:

```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:

```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());
```

C# / .NET:

```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"
    }
}));
```

Golang:

```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

TypeScript:

```ts
new ManagedKafkaEventSource(props: ManagedKafkaEventSourceProps)
```

Python:

```python
ManagedKafkaEventSource(props: ManagedKafkaEventSourceProps)
```

Java:

```java
new ManagedKafkaEventSource(ManagedKafkaEventSourceProps props)
```

C# / .NET:

```csharp
new ManagedKafkaEventSource(ManagedKafkaEventSourceProps props)
```

Golang:

```go
NewManagedKafkaEventSource(Props ManagedKafkaEventSourceProps)
```

## Properties

- `eventSourceMappingArn`: string — The ARN for this EventSourceMapping.

- `eventSourceMappingId`: string — The identifier for this EventSourceMapping.

## Methods

- `bind(target: IFunction): void` — Called by `lambda.addEventSource` to allow the event source to bind to this function.
