# KeySchema

A description of a key schema of an LSI, GSI or Table.

Returned by: [Table.schemaV2](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Table.html#schemav2)

- Source: [`aws-dynamodb/lib/shared.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts#L571)
- Type last changed: v2.226.0 · 20 Nov 2025

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_dynamodb as dynamodb } from 'aws-cdk-lib';
const keySchema: dynamodb.KeySchema = {
  partitionKeys: [{
    name: 'name',
    type: dynamodb.AttributeType.BINARY,
  }],
  sortKeys: [{
    name: 'name',
    type: dynamodb.AttributeType.BINARY,
  }],
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_dynamodb as dynamodb

key_schema = dynamodb.KeySchema(
    partition_keys=[dynamodb.Attribute(
        name="name",
        type=dynamodb.AttributeType.BINARY
    )],
    sort_keys=[dynamodb.Attribute(
        name="name",
        type=dynamodb.AttributeType.BINARY
    )]
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.dynamodb.*;

KeySchema keySchema = KeySchema.builder()
        .partitionKeys(List.of(Attribute.builder()
                .name("name")
                .type(AttributeType.BINARY)
                .build()))
        .sortKeys(List.of(Attribute.builder()
                .name("name")
                .type(AttributeType.BINARY)
                .build()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.DynamoDB;

var keySchema = new KeySchema {
    PartitionKeys = new [] { new Attribute {
        Name = "name",
        Type = AttributeType.BINARY
    } },
    SortKeys = new [] { new Attribute {
        Name = "name",
        Type = AttributeType.BINARY
    } }
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

keySchema := &KeySchema{
	PartitionKeys: []Attribute{
		&Attribute{
			Name: jsii.String("name"),
			Type: awscdk.Aws_dynamodb.AttributeType_BINARY,
		},
	},
	SortKeys: []Attribute{
		&Attribute{
			Name: jsii.String("name"),
			Type: awscdk.*Aws_dynamodb.AttributeType_BINARY,
		},
	},
}
```

## Properties

- `partitionKeys`: [Attribute](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Attribute.html)[] (required) — Partition key definition.

  This array has at least one, but potentially multiple entries.  Together,
  they form the partition key.

- `sortKeys`: [Attribute](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Attribute.html)[] (required) — Sort key definition.

  This array has zero or more entries. Together, they form the sort key.
