SelfManagedKafkaEventSourceProps Struct
Properties for a self managed Kafka cluster event source.
If your Kafka cluster is only reachable via VPC make sure to configure it.
Example
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
},
}));
from aws_cdk.aws_lambda_event_sources import ProvisionedPollerConfig
from aws_cdk.aws_lambda_event_sources import SelfManagedKafkaEventSource, AuthenticationMethod
from aws_cdk.aws_lambda import StartingPosition, Function
from aws_cdk.aws_secretsmanager import ISecret
# With provisioned pollers and poller group for cost optimization
# my_function: Function
# kafka_credentials: ISecret
my_function.add_event_source(SelfManagedKafkaEventSource(
bootstrap_servers=["kafka-broker1.example.com:9092", "kafka-broker2.example.com:9092"],
topic="events-topic",
secret=kafka_credentials,
starting_position=StartingPosition.LATEST,
authentication_method=AuthenticationMethod.SASL_SCRAM_512_AUTH,
provisioned_poller_config=ProvisionedPollerConfig(
minimum_pollers=1,
maximum_pollers=8,
poller_group_name="self-managed-kafka-group"
)
))
import software.amazon.awscdk.services.lambda.eventsources.SelfManagedKafkaEventSource;
import software.amazon.awscdk.services.lambda.eventsources.AuthenticationMethod;
import software.amazon.awscdk.services.lambda.StartingPosition;
import software.amazon.awscdk.services.lambda.Function;
import software.amazon.awscdk.services.secretsmanager.ISecret;
// With provisioned pollers and poller group for cost optimization
Function myFunction;
ISecret kafkaCredentials;
myFunction.addEventSource(SelfManagedKafkaEventSource.Builder.create()
.bootstrapServers(List.of("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(ProvisionedPollerConfig.builder()
.minimumPollers(1)
.maximumPollers(8)
.pollerGroupName("self-managed-kafka-group")
.build())
.build());
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda.EventSources;
using Amazon.CDK.AWS.Lambda;
using Amazon.CDK.AWS.SecretsManager;
// With provisioned pollers and poller group for cost optimization
Function myFunction;
ISecret kafkaCredentials;
myFunction.AddEventSource(new SelfManagedKafkaEventSource(new SelfManagedKafkaEventSourceProps {
BootstrapServers = new [] { "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 = new ProvisionedPollerConfig {
MinimumPollers = 1,
MaximumPollers = 8,
PollerGroupName = "self-managed-kafka-group"
}
}));
// 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"
import "github.com/aws/aws-cdk-go/awscdk"
// With provisioned pollers and poller group for cost optimization
var myFunction Function
var kafkaCredentials ISecret
myFunction.AddEventSource(awscdk.NewSelfManagedKafkaEventSource(&SelfManagedKafkaEventSourceProps{
BootstrapServers: []*string{
jsii.String("kafka-broker1.example.com:9092"),
jsii.String("kafka-broker2.example.com:9092"),
},
Topic: jsii.String("events-topic"),
Secret: kafkaCredentials,
StartingPosition: awscdk.StartingPosition_LATEST,
AuthenticationMethod: awscdk.AuthenticationMethod_SASL_SCRAM_512_AUTH,
ProvisionedPollerConfig: &ProvisionedPollerConfig{
MinimumPollers: jsii.Number(1),
MaximumPollers: jsii.Number(8),
PollerGroupName: jsii.String("self-managed-kafka-group"),
},
}))
Properties
authenticationMethodoptionalAuthenticationMethodauthentication_methodoptionalAuthenticationMethodauthenticationMethodoptionalAuthenticationMethodAuthenticationMethodoptionalAuthenticationMethodAuthenticationMethodoptionalAuthenticationMethod#Default: AuthenticationMethod.SASL_SCRAM_512_AUTH
batchSizeoptionalnumberbatch_sizeoptionalint | floatbatchSizeoptionalNumberBatchSizeoptionaldoubleBatchSizeoptional*float64= 100#notes
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,ManagedKafkaEventSourceandSelfManagedKafkaEventSource
- 1000 for
bisectBatchOnErroroptionalbooleanbisect_batch_on_erroroptionalboolbisectBatchOnErroroptionalBooleanBisectBatchOnErroroptionalboolBisectBatchOnErroroptional*bool= false#bootstrapServersstring[]bootstrap_serverstyping.List[str]bootstrapServersList<String>BootstrapServersstring[]BootstrapServers*[]*stringrequired#They are in the format abc.xyz.com:xxxx.
consumerGroupIdoptionalstringconsumer_group_idoptionalstrconsumerGroupIdoptionalStringConsumerGroupIdoptionalstringConsumerGroupIdoptional*string= none#notes
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-/:_+=.@-]'.
enabledoptionalbooleanenabledoptionalboolenabledoptionalBooleanEnabledoptionalboolEnabledoptional*bool= true#filterEncryptionoptionalIKeyfilter_encryptionoptionalIKeyfilterEncryptionoptionalIKeyFilterEncryptionoptionalIKeyFilterEncryptionoptionalIKey= none#filtersoptional{ [key: string]: any }[]filtersoptionaltyping.List[typing.Mapping[str, Any]]filtersoptionalList<Map<String, Object>>FiltersoptionalIDictionary<string, object>[]Filtersoptional*[]*map[string]interface{}= none#logLeveloptionalEventSourceMappingLogLevellog_leveloptionalEventSourceMappingLogLevellogLeveloptionalEventSourceMappingLogLevelLogLeveloptionalEventSourceMappingLogLevelLogLeveloptionalEventSourceMappingLogLevel#Default: No logging
maxBatchingWindowoptionalDurationmax_batching_windowoptionalDurationmaxBatchingWindowoptionalDurationMaxBatchingWindowoptionalDurationMaxBatchingWindowoptionalDuration#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).
maxRecordAgeoptionalDurationmax_record_ageoptionalDurationmaxRecordAgeoptionalDurationMaxRecordAgeoptionalDurationMaxRecordAgeoptionalDuration= -1#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.
metricsConfigoptionalMetricsConfigmetrics_configoptionalMetricsConfigmetricsConfigoptionalMetricsConfigMetricsConfigoptionalMetricsConfigMetricsConfigoptionalMetricsConfig#Default: Enhanced monitoring is disabled
onFailureoptionalIEventSourceDlqon_failureoptionalIEventSourceDlqonFailureoptionalIEventSourceDlqOnFailureoptionalIEventSourceDlqOnFailureoptionalIEventSourceDlq#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
provisionedPollerConfigoptionalProvisionedPollerConfigprovisioned_poller_configoptionalProvisionedPollerConfigprovisionedPollerConfigoptionalProvisionedPollerConfigProvisionedPollerConfigoptionalProvisionedPollerConfigProvisionedPollerConfigoptionalProvisionedPollerConfig#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.
reportBatchItemFailuresoptionalbooleanreport_batch_item_failuresoptionalboolreportBatchItemFailuresoptionalBooleanReportBatchItemFailuresoptionalboolReportBatchItemFailuresoptional*bool= false#retryAttemptsoptionalnumberretry_attemptsoptionalint | floatretryAttemptsoptionalNumberRetryAttemptsoptionaldoubleRetryAttemptsoptional*float64#Default: -1 (infinite retries)
Set to -1 for infinite retries (until the record expires in the event source).
rootCACertificateoptionalISecretroot_ca_certificateoptionalISecretrootCACertificateoptionalISecretRootCACertificateoptionalISecretRootCACertificateoptionalISecret= none#schemaRegistryConfigoptionalISchemaRegistryschema_registry_configoptionalISchemaRegistryschemaRegistryConfigoptionalISchemaRegistrySchemaRegistryConfigoptionalISchemaRegistrySchemaRegistryConfigoptionalISchemaRegistry= none#secretoptionalISecretsecretoptionalISecretsecretoptionalISecretSecretoptionalISecretSecretoptionalISecret= none#securityGroupoptionalISecurityGroupsecurity_groupoptionalISecurityGroupsecurityGroupoptionalISecurityGroupSecurityGroupoptionalISecurityGroupSecurityGroupoptionalISecurityGroup#Default: none, required if setting vpc
startingPositionStartingPositionstarting_positionStartingPositionstartingPositionStartingPositionStartingPositionStartingPositionStartingPositionStartingPositionrequired#startingPositionTimestampoptionalnumberstarting_position_timestampoptionalint | floatstartingPositionTimestampoptionalNumberStartingPositionTimestampoptionaldoubleStartingPositionTimestampoptional*float64#Default: no timestamp
vpcSubnetsoptionalSubnetSelectionvpc_subnetsoptionalSubnetSelectionvpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelection#Default: none, required if setting vpc