# ManagedKafkaEventSourceProps

Properties for a MSK event source.

Extends: [KafkaEventSourceProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.KafkaEventSourceProps.html)
Used as props by: [ManagedKafkaEventSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.ManagedKafkaEventSource.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#L136)

## Example

TypeScript:

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

// Your MSK cluster arn
const clusterArn = 'arn:aws:kafka:us-east-1:0123456789019:cluster/SalesCluster/abcd1234-abcd-cafe-abab-9876543210ab-4';

declare const myFunction: lambda.Function;

// Enable basic event and error metrics
myFunction.addEventSource(new ManagedKafkaEventSource({
  clusterArn,
  topic: 'basic-monitoring',
  startingPosition: lambda.StartingPosition.LATEST,
  // Provisioned mode is required for observability features
  provisionedPollerConfig: {
    minimumPollers: 2,
    maximumPollers: 10,
  },
  metricsConfig: {
    metrics: [
      lambda.MetricType.EVENT_COUNT,
      lambda.MetricType.ERROR_COUNT
    ]
  }
}));
```

Python:

```python
from aws_cdk.aws_lambda_event_sources import ProvisionedPollerConfig
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"

# Enable basic event and error metrics
my_function.add_event_source(ManagedKafkaEventSource(
    cluster_arn=cluster_arn,
    topic="basic-monitoring",
    starting_position=lambda_.StartingPosition.LATEST,
    # Provisioned mode is required for observability features
    provisioned_poller_config=ProvisionedPollerConfig(
        minimum_pollers=2,
        maximum_pollers=10
    ),
    metrics_config=lambda.MetricsConfig(
        metrics=[lambda_.MetricType.EVENT_COUNT, lambda_.MetricType.ERROR_COUNT
        ]
    )
))
```

Java:

```java
import software.amazon.awscdk.services.lambda.eventsources.ManagedKafkaEventSource;

Function myFunction;

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

// Enable basic event and error metrics
myFunction.addEventSource(ManagedKafkaEventSource.Builder.create()
        .clusterArn(clusterArn)
        .topic("basic-monitoring")
        .startingPosition(StartingPosition.LATEST)
        // Provisioned mode is required for observability features
        .provisionedPollerConfig(ProvisionedPollerConfig.builder()
                .minimumPollers(2)
                .maximumPollers(10)
                .build())
        .metricsConfig(MetricsConfig.builder()
                .metrics(List.of(MetricType.EVENT_COUNT, MetricType.ERROR_COUNT))
                .build())
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda.EventSources;

Function myFunction;

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

// Enable basic event and error metrics
myFunction.AddEventSource(new ManagedKafkaEventSource(new ManagedKafkaEventSourceProps {
    ClusterArn = clusterArn,
    Topic = "basic-monitoring",
    StartingPosition = StartingPosition.LATEST,
    // Provisioned mode is required for observability features
    ProvisionedPollerConfig = new ProvisionedPollerConfig {
        MinimumPollers = 2,
        MaximumPollers = 10
    },
    MetricsConfig = new MetricsConfig {
        Metrics = new [] { MetricType.EVENT_COUNT, MetricType.ERROR_COUNT }
    }
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

var myFunction Function

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

// Enable basic event and error metrics
myFunction.AddEventSource(awscdk.NewManagedKafkaEventSource(&ManagedKafkaEventSourceProps{
	ClusterArn: jsii.String(ClusterArn),
	Topic: jsii.String("basic-monitoring"),
	StartingPosition: lambda.StartingPosition_LATEST,
	// Provisioned mode is required for observability features
	ProvisionedPollerConfig: &ProvisionedPollerConfig{
		MinimumPollers: jsii.Number(2),
		MaximumPollers: jsii.Number(10),
	},
	MetricsConfig: &MetricsConfig{
		Metrics: []MetricType{
			lambda.MetricType_EVENT_COUNT,
			lambda.MetricType_ERROR_COUNT,
		},
	},
}))
```

## Properties

- `batchSize`: number = 100 — 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 `DynamoEventSource`
    * 10000 for `KinesisEventSource`, `ManagedKafkaEventSource` and `SelfManagedKafkaEventSource`

- `bisectBatchOnError`: boolean = false — * If the function returns an error, split the batch in two and retry.

- `clusterArn`: string (required) — An MSK cluster construct.

- `consumerGroupId`: string = none — The identifier for the Kafka consumer group to join.

  The consumer group ID must be unique among all your Kafka event sources. After creating a Kafka event source mapping with the consumer group ID specified, you cannot update this value.  The value must have a length between 1 and 200 and full the pattern '[a-zA-Z0-9-\/*:_+=.@-]*'.
  When `consumptionMode` is `KafkaConsumptionMode.QUEUE`, this is the name of the share group.

- `enabled`: boolean = true — If the stream event source mapping should be enabled.

- `filterEncryption`: [IKey](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) = none — Add Customer managed KMS key to encrypt Filter Criteria.

- `filters`: { [key: string]: any }[] = none — Add filter criteria to Event Source.

- `logLevel`: [EventSourceMappingLogLevel](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.EventSourceMappingLogLevel.html) — Configuration for logging verbosity from the event source mapping poller.

  **Default:** No logging

- `maxBatchingWindow`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The maximum amount of time to gather records before invoking the function.

  **Default:** Duration.seconds(0) for Kinesis, DynamoDB, and SQS event sources, Duration.millis(500) for MSK, self-managed Kafka, and Amazon MQ.

  Maximum of Duration.minutes(5).

- `maxRecordAge`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = -1 — The maximum age of a record that Lambda sends to a function for processing.

  The default value is -1, which sets the maximum age to infinite.
  When the value is set to infinite, Lambda never discards old records.
  Record are valid until it expires in the event source.

- `metricsConfig`: [MetricsConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.MetricsConfig.html) — Configuration for enhanced monitoring metrics collection.

  **Default:** Enhanced monitoring is disabled

- `onFailure`: [IEventSourceDlq](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.IEventSourceDlq.html) — Add an on Failure Destination for this Kafka event.

  **Default:** discarded records are ignored

  Supported destinations:
  - {@link KafkaDlq } - Send failed records to a Kafka topic
  - SNS topics - Send failed records to an SNS topic
  - SQS queues - Send failed records to an SQS queue
  - S3 buckets - Send failed records to an S3 bucket

- `provisionedPollerConfig`: [ProvisionedPollerConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.ProvisionedPollerConfig.html) — Configuration for provisioned pollers that read from the event source.

  **Default:** no provisioned pollers

  When specified, allows control over the minimum and maximum number of pollers
  that can be provisioned to process events from the source.

- `reportBatchItemFailures`: boolean = false — * Allow functions to return partially successful responses for a batch of records.

- `retryAttempts`: number — * Maximum number of retry attempts.

  **Default:** -1 (infinite retries) in stream mode, 0 in queue mode

  Set to -1 for infinite retries (until the record expires in the event source).
  `-1` isn't supported when `consumptionMode` is `KafkaConsumptionMode.QUEUE`.

- `schemaRegistryConfig`: [ISchemaRegistry](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.ISchemaRegistry.html) = none — Specific configuration settings for a Kafka schema registry.

- `secret`: [ISecret](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) = none — 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.

- `startingPosition`: [StartingPosition](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.StartingPosition.html) — Where to begin consuming the stream.

  **Default:** no starting position; synthesis fails if the event source requires one

  Required for DynamoDB, Kinesis and Amazon MSK event sources, and for self-managed Kafka
  event sources unless `consumptionMode` is `KafkaConsumptionMode.QUEUE`. Not supported in
  queue mode.

- `startingPositionTimestamp`: number — The time from which to start reading, in Unix time seconds.

  **Default:** no timestamp

- `topic`: string (required) — The Kafka topic to subscribe to.
