# TableProps

Properties for a DynamoDB Table.

Extends: TableProps
Extends: TableOptions
Used as props by: Table

- Source: [`aws-dynamodb/lib/table.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts#L500)
- Type last changed: v2.173.0 · 12 Dec 2024

## Example

```ts
import * as eventsources from 'aws-cdk-lib/aws-lambda-event-sources';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import { Key } from 'aws-cdk-lib/aws-kms';

declare const fn: lambda.Function;
const table = new dynamodb.Table(this, 'Table', {
  partitionKey: {
    name: 'id',
    type: dynamodb.AttributeType.STRING,
  },
  stream: dynamodb.StreamViewType.NEW_IMAGE,
});
// Your self managed KMS key
const myKey = Key.fromKeyArn(
  this,
  'SourceBucketEncryptionKey',
  'arn:aws:kms:us-east-1:123456789012:key/<key-id>',
);

fn.addEventSource(new eventsources.DynamoEventSource(table, {
  startingPosition: lambda.StartingPosition.LATEST,
  filters: [lambda.FilterCriteria.filter({ eventName: lambda.FilterRule.isEqual('INSERT') })],
  filterEncryption: myKey,
}));
```

## Properties

- `billingMode`: [BillingMode](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.BillingMode.html) — Specify how you are charged for read and write throughput and how you manage capacity.

  **Default:** PROVISIONED if `replicationRegions` is not specified, PAY_PER_REQUEST otherwise

- `contributorInsightsEnabled`: boolean = false — use `contributorInsightsSpecification instead

- `contributorInsightsSpecification`: [ContributorInsightsSpecification](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.ContributorInsightsSpecification.html) — Whether CloudWatch contributor insights is enabled and what mode is selected.

  **Default:** contributor insights is not enabled

- `deletionProtection`: boolean = false — Enables deletion protection for the table.

- `encryption`: [TableEncryption](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.TableEncryption.html) — Whether server-side encryption with an AWS managed customer master key is enabled.

  **Default:** The table is encrypted with an encryption key managed by DynamoDB, and you are not charged any fee for using it.

  This property cannot be set if `serverSideEncryption` is set.

  > **NOTE**: if you set this to `CUSTOMER_MANAGED` and `encryptionKey` is not
  > specified, the key that the Tablet generates for you will be created with
  > default permissions. If you are using CDKv2, these permissions will be
  > sufficient to enable the key for use with DynamoDB tables.  If you are
  > using CDKv1, make sure the feature flag
  > `@aws-cdk/aws-kms:defaultKeyPolicies` is set to `true` in your `cdk.json`.

- `encryptionKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — External KMS key to use for table encryption.

  **Default:** If `encryption` is set to `TableEncryption.CUSTOMER_MANAGED` and this property is undefined, a new KMS key will be created and associated with this table. If `encryption` and this property are both undefined, then the table is encrypted with an encryption key managed by DynamoDB, and you are not charged any fee for using it.

  This property can only be set if `encryption` is set to `TableEncryption.CUSTOMER_MANAGED`.

- `importSource`: [ImportSourceSpecification](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.ImportSourceSpecification.html) — The properties of data being imported from the S3 bucket source to the table.

  **Default:** no data import from the S3 bucket

- `kinesisPrecisionTimestamp`: [ApproximateCreationDateTimePrecision](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.ApproximateCreationDateTimePrecision.html) — Kinesis Data Stream approximate creation timestamp precision.

  **Default:** ApproximateCreationDateTimePrecision.MICROSECOND

- `kinesisStream`: [IStream](/cdk/api/v2/docs/aws-cdk-lib.aws_kinesis.IStream.html) — Kinesis Data Stream to capture item-level changes for the table.

  **Default:** no Kinesis Data Stream

- `maxReadRequestUnits`: number — The maximum read request units for the table.

  **Default:** on-demand throughput is disabled

  Careful if you add Global Secondary Indexes, as
  those will share the table's maximum on-demand throughput.

  Can only be provided if billingMode is PAY_PER_REQUEST.

- `maxWriteRequestUnits`: number — The write request units for the table.

  **Default:** on-demand throughput is disabled

  Careful if you add Global Secondary Indexes, as
  those will share the table's maximum on-demand throughput.

  Can only be provided if billingMode is PAY_PER_REQUEST.

- `partitionKey`: [Attribute](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Attribute.html) — Partition key attribute definition.

  **Default:** exactly one of `partitionKey` and `partitionKeys` must be specified.

  If a single field forms the partition key, you can use this field.  Use the
  `partitionKeys` field if the partition key is a multi-attribute key (consists of
  multiple fields).

- `pointInTimeRecovery`: boolean — use `pointInTimeRecoverySpecification` instead

  **Default:** false - point in time recovery is not enabled.

- `pointInTimeRecoverySpecification`: [PointInTimeRecoverySpecification](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.PointInTimeRecoverySpecification.html) — Whether point-in-time recovery is enabled and recoveryPeriodInDays is set.

  **Default:** point in time recovery is not enabled.

- `readCapacity`: number = 5 — The read capacity for the table.

  Careful if you add Global Secondary Indexes, as
  those will share the table's provisioned throughput.

  Can only be provided if billingMode is Provisioned.

- `removalPolicy`: [RemovalPolicy](/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) = RemovalPolicy.RETAIN — The removal policy to apply to the DynamoDB Table.

- `replicaRemovalPolicy`: [RemovalPolicy](/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) — The removal policy to apply to the DynamoDB replica tables.

  **Default:** undefined - use DynamoDB Table's removal policy

- `replicationRegions`: string[] — Regions where replica tables will be created.

  **Default:** no replica tables are created

- `replicationTimeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.minutes(30) — The timeout for a table replication operation in a single region.

- `resourcePolicy`: [PolicyDocument](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyDocument.html) — Resource policy to assign to table.

  **Default:** No resource policy statement

- `sortKey`: [Attribute](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Attribute.html) — Sort key attribute definition.

  **Default:** no sort key

  If a single field forms the sort key, you can use this field.  Use the
  `sortKeys` field if the sort key is a multi-attribute key (consists of multiple
  fields).

- `stream`: [StreamViewType](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.StreamViewType.html) — When an item in the table is modified, StreamViewType determines what information is written to the stream for this table.

  **Default:** streams are disabled unless `replicationRegions` is specified

- `tableClass`: [TableClass](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.TableClass.html) = STANDARD — Specify the table class.

- `tableName`: string = <generated> — Enforces a particular physical table name.

- `timeToLiveAttribute`: string — The name of TTL attribute.

  **Default:** TTL is disabled

- `waitForReplicationToFinish`: boolean = true — [WARNING: Use this flag with caution, misusing this flag may cause deleting existing replicas, refer to the detailed documentation for more information] Indicates whether CloudFormation stack waits for replication to finish.

  If set to false, the CloudFormation resource will mark the resource as
  created and replication will be completed asynchronously. This property is
  ignored if replicationRegions property is not set.

  WARNING:
  DO NOT UNSET this property if adding/removing multiple replicationRegions
  in one deployment, as CloudFormation only supports one region replication
  at a time. CDK overcomes this limitation by waiting for replication to
  finish before starting new replicationRegion.

  If the custom resource which handles replication has a physical resource
  ID with the format `region` instead of `tablename-region` (this would happen
  if the custom resource hasn't received an event since v1.91.0), DO NOT SET
  this property to false without making a change to the table name.
  This will cause the existing replicas to be deleted.

- `warmThroughput`: [WarmThroughput](/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.WarmThroughput.html) — Specify values to pre-warm you DynamoDB Table Warm Throughput feature is not available for Global Table replicas using the `Table` construct.

  **Default:** warm throughput is not configured

  To enable Warm Throughput, use the `TableV2` construct instead.

- `writeCapacity`: number = 5 — The write capacity for the table.

  Careful if you add Global Secondary Indexes, as
  those will share the table's provisioned throughput.

  Can only be provided if billingMode is Provisioned.
