Skip to content
v2.277.0

StartingPosition Enum ​

The position in the DynamoDB, Kinesis or MSK stream where AWS Lambda should start reading.

Example ​

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
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
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());
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 }
    }
}));
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,
		},
	},
}))

Members ​

MemberDescription
TRIM_HORIZONStart reading at the last untrimmed record in the shard in the system, which is the oldest data record in the shard.
LATESTStart reading just after the most recent record in the shard, so that you always read the most recent data in the shard.
AT_TIMESTAMPStart reading from a position defined by a time stamp.

Referenced by ​