# SelfManagedKafkaEventSourceProps

Properties for a self managed Kafka cluster event source.

If your Kafka cluster is only reachable via VPC make sure to configure it.

Extends: SelfManagedKafkaEventSourceProps
Extends: KafkaEventSourceProps
Used as props by: SelfManagedKafkaEventSource

- Source: [`aws-lambda-event-sources/lib/kafka.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda-event-sources/lib/kafka.ts#L167)
- Type last changed: v2.38.0 · 17 Aug 2022

## Example

```ts
import { SelfManagedKafkaEventSource, AuthenticationMethod } from 'aws-cdk-lib/aws-lambda-event-sources';
import { StartingPosition, Function } from 'aws-cdk-lib/aws-lambda';
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager';

// With provisioned pollers and poller group for cost optimization
declare const myFunction: Function;
declare const kafkaCredentials: ISecret;
myFunction.addEventSource(new SelfManagedKafkaEventSource({
  bootstrapServers: ['kafka-broker1.example.com:9092', 'kafka-broker2.example.com:9092'],
  topic: 'events-topic',
  secret: kafkaCredentials,
  startingPosition: StartingPosition.LATEST,
  authenticationMethod: AuthenticationMethod.SASL_SCRAM_512_AUTH,
  provisionedPollerConfig: {
    minimumPollers: 1,
    maximumPollers: 8,
    pollerGroupName: 'self-managed-kafka-group', // Group pollers to reduce costs
  },
}));
```

## Properties

- `authenticationMethod`: [AuthenticationMethod](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.AuthenticationMethod.html) — The authentication method for your Kafka cluster.

  **Default:** AuthenticationMethod.SASL_SCRAM_512_AUTH

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

- `bootstrapServers`: string[] (required) — The list of host and port pairs that are the addresses of the Kafka brokers in a "bootstrap" Kafka cluster that a Kafka client connects to initially to bootstrap itself.

  They are in the format `abc.xyz.com:xxxx`.

- `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-\/*:_+=.@-]*'.

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

- `filterEncryption`: [IKey](/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](/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](/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](/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](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.MetricsConfig.html) — Configuration for enhanced monitoring metrics collection.

  **Default:** Enhanced monitoring is disabled

- `onFailure`: [IEventSourceDlq](/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](/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)

  Set to -1 for infinite retries (until the record expires in the event source).

- `rootCACertificate`: [ISecret](/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) = none — The secret with the root CA certificate used by your Kafka brokers for TLS encryption This field is required if your Kafka brokers use certificates signed by a private CA.

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

- `secret`: [ISecret](/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.

- `securityGroup`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html) — If your Kafka brokers are only reachable via VPC, provide the security group here.

  **Default:** none, required if setting vpc

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

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

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) = none — If your Kafka brokers are only reachable via VPC provide the VPC here.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — If your Kafka brokers are only reachable via VPC, provide the subnets selection here.

  **Default:** none, required if setting vpc
