# StartingPosition

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

- Source: [`aws-lambda/lib/event-source-mapping.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-lambda/lib/event-source-mapping.ts#L695)
- Type last changed: v2.34.0 · 29 Jul 2022

## 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
    ]
  }
}));
```

## Members

| Member | Description |
| --- | --- |
| `TRIM_HORIZON` | Start reading at the last untrimmed record in the shard in the system, which is the oldest data record in the shard. |
| `LATEST` | Start reading just after the most recent record in the shard, so that you always read the most recent data in the shard. |
| `AT_TIMESTAMP` | Start reading from a position defined by a time stamp. |

## Referenced by

- [`BaseStreamEventSourceProps`](/v2/docs/aws-cdk-lib.aws_lambda_event_sources.BaseStreamEventSourceProps).startingPosition
- [`EventSourceMappingOptions`](/v2/docs/aws-cdk-lib.aws_lambda.EventSourceMappingOptions).startingPosition
