Skip to content
v2.274.0

KafkaEventSourceProps Struct ​

Properties for a Kafka event source.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_kms as kms } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';
import { aws_lambda_event_sources as lambda_event_sources } from 'aws-cdk-lib';
import { aws_secretsmanager as secretsmanager } from 'aws-cdk-lib';

declare const eventSourceDlq: lambda.IEventSourceDlq;
declare const filters: any;
declare const key: kms.Key;
declare const schemaRegistry: lambda.ISchemaRegistry;
declare const secret: secretsmanager.Secret;
const kafkaEventSourceProps: lambda_event_sources.KafkaEventSourceProps = {
  startingPosition: lambda.StartingPosition.TRIM_HORIZON,
  topic: 'topic',

  // the properties below are optional
  batchSize: 123,
  bisectBatchOnError: false,
  consumerGroupId: 'consumerGroupId',
  enabled: false,
  filterEncryption: key,
  filters: [{
    filtersKey: filters,
  }],
  logLevel: lambda.EventSourceMappingLogLevel.INFO,
  maxBatchingWindow: cdk.Duration.minutes(30),
  maxRecordAge: cdk.Duration.minutes(30),
  metricsConfig: {
    metrics: [lambda.MetricType.EVENT_COUNT],
  },
  onFailure: eventSourceDlq,
  provisionedPollerConfig: {
    maximumPollers: 123,
    minimumPollers: 123,
    pollerGroupName: 'pollerGroupName',
  },
  reportBatchItemFailures: false,
  retryAttempts: 123,
  schemaRegistryConfig: schemaRegistry,
  secret: secret,
  startingPositionTimestamp: 123,
};

Properties ​

batchSizeoptionalnumberbatch_sizeoptionalint | floatbatchSizeoptionalNumberBatchSizeoptionaldoubleBatchSizeoptional*float64= 100#
The largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.
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, ManagedKafkaEventSource and SelfManagedKafkaEventSource
bisectBatchOnErroroptionalbooleanbisect_batch_on_erroroptionalboolbisectBatchOnErroroptionalBooleanBisectBatchOnErroroptionalboolBisectBatchOnErroroptional*bool= false#
* If the function returns an error, split the batch in two and retry.
consumerGroupIdoptionalstringconsumer_group_idoptionalstrconsumerGroupIdoptionalStringConsumerGroupIdoptionalstringConsumerGroupIdoptional*string= none#
The identifier for the Kafka consumer group to join.
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#
If the stream event source mapping should be enabled.
filterEncryptionoptionalIKeyfilter_encryptionoptionalIKeyfilterEncryptionoptionalIKeyFilterEncryptionoptionalIKeyFilterEncryptionoptionalIKey= none#
Add Customer managed KMS key to encrypt Filter Criteria.
filtersoptional{ [key: string]: any }[]filtersoptionaltyping.List[typing.Mapping[str, Any]]filtersoptionalList<Map<String, Object>>FiltersoptionalIDictionary<string, object>[]Filtersoptional*[]*map[string]interface{}= none#
Add filter criteria to Event Source.
Configuration for logging verbosity from the event source mapping poller.

Default: No logging

maxBatchingWindowoptionalDurationmax_batching_windowoptionalDurationmaxBatchingWindowoptionalDurationMaxBatchingWindowoptionalDurationMaxBatchingWindowoptionalDuration#
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).

maxRecordAgeoptionalDurationmax_record_ageoptionalDurationmaxRecordAgeoptionalDurationMaxRecordAgeoptionalDurationMaxRecordAgeoptionalDuration= -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.

metricsConfigoptionalMetricsConfigmetrics_configoptionalMetricsConfigmetricsConfigoptionalMetricsConfigMetricsConfigoptionalMetricsConfigMetricsConfigoptionalMetricsConfig#
Configuration for enhanced monitoring metrics collection.

Default: Enhanced monitoring is disabled

onFailureoptionalIEventSourceDlqon_failureoptionalIEventSourceDlqonFailureoptionalIEventSourceDlqOnFailureoptionalIEventSourceDlqOnFailureoptionalIEventSourceDlq#
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
provisionedPollerConfigoptionalProvisionedPollerConfigprovisioned_poller_configoptionalProvisionedPollerConfigprovisionedPollerConfigoptionalProvisionedPollerConfigProvisionedPollerConfigoptionalProvisionedPollerConfigProvisionedPollerConfigoptionalProvisionedPollerConfig#
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.

reportBatchItemFailuresoptionalbooleanreport_batch_item_failuresoptionalboolreportBatchItemFailuresoptionalBooleanReportBatchItemFailuresoptionalboolReportBatchItemFailuresoptional*bool= false#
* Allow functions to return partially successful responses for a batch of records.
retryAttemptsoptionalnumberretry_attemptsoptionalint | floatretryAttemptsoptionalNumberRetryAttemptsoptionaldoubleRetryAttemptsoptional*float64#
* Maximum number of retry attempts.

Default: -1 (infinite retries)

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

schemaRegistryConfigoptionalISchemaRegistryschema_registry_configoptionalISchemaRegistryschemaRegistryConfigoptionalISchemaRegistrySchemaRegistryConfigoptionalISchemaRegistrySchemaRegistryConfigoptionalISchemaRegistry= none#
Specific configuration settings for a Kafka schema registry.
secretoptionalISecretsecretoptionalISecretsecretoptionalISecretSecretoptionalISecretSecretoptionalISecret= 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.
startingPositionStartingPositionstarting_positionStartingPositionstartingPositionStartingPositionStartingPositionStartingPositionStartingPositionStartingPositionrequired#
Where to begin consuming the stream.
startingPositionTimestampoptionalnumberstarting_position_timestampoptionalint | floatstartingPositionTimestampoptionalNumberStartingPositionTimestampoptionaldoubleStartingPositionTimestampoptional*float64#
The time from which to start reading, in Unix time seconds.

Default: no timestamp

topicstringtopicstrtopicStringTopicstringTopic*stringrequired#
The Kafka topic to subscribe to.