# GlobalSecondaryIndexPropsV2

Properties used to configure a global secondary index.

Extends: [SecondaryIndexProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.SecondaryIndexProps.html)
Used as argument in: [TableV2.addGlobalSecondaryIndex](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.TableV2.html#addglobalsecondaryindex)

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

## Example

TypeScript:

```ts
const table = new dynamodb.TableV2(this, 'Table', {
  partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
  globalSecondaryIndexes: [
    {
      indexName: 'gsi1',
      partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
    },
  ],
});

table.addGlobalSecondaryIndex({
  indexName: 'gsi2',
  partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
});

// Add a GSI with multi-attribute keys
table.addGlobalSecondaryIndex({
  indexName: 'multi-attribute-gsi2',
  partitionKeys: [
    { name: 'multi-attribute_pk1', type: dynamodb.AttributeType.STRING },
    { name: 'multi-attribute_pk2', type: dynamodb.AttributeType.NUMBER },
  ],
  sortKey: { name: 'sk', type: dynamodb.AttributeType.STRING },
});
```

Python:

```python
table = dynamodb.TableV2(self, "Table",
    partition_key=dynamodb.Attribute(name="pk", type=dynamodb.AttributeType.STRING),
    global_secondary_indexes=[dynamodb.GlobalSecondaryIndexPropsV2(
        index_name="gsi1",
        partition_key=dynamodb.Attribute(name="pk", type=dynamodb.AttributeType.STRING)
    )
    ]
)

table.add_global_secondary_index(
    index_name="gsi2",
    partition_key=dynamodb.Attribute(name="pk", type=dynamodb.AttributeType.STRING)
)

# Add a GSI with multi-attribute keys
table.add_global_secondary_index(
    index_name="multi-attribute-gsi2",
    partition_keys=[dynamodb.Attribute(name="multi-attribute_pk1", type=dynamodb.AttributeType.STRING), dynamodb.Attribute(name="multi-attribute_pk2", type=dynamodb.AttributeType.NUMBER)
    ],
    sort_key=dynamodb.Attribute(name="sk", type=dynamodb.AttributeType.STRING)
)
```

Java:

```java
TableV2 table = TableV2.Builder.create(this, "Table")
        .partitionKey(Attribute.builder().name("pk").type(AttributeType.STRING).build())
        .globalSecondaryIndexes(List.of(GlobalSecondaryIndexPropsV2.builder()
                .indexName("gsi1")
                .partitionKey(Attribute.builder().name("pk").type(AttributeType.STRING).build())
                .build()))
        .build();

table.addGlobalSecondaryIndex(GlobalSecondaryIndexPropsV2.builder()
        .indexName("gsi2")
        .partitionKey(Attribute.builder().name("pk").type(AttributeType.STRING).build())
        .build());

// Add a GSI with multi-attribute keys
table.addGlobalSecondaryIndex(GlobalSecondaryIndexPropsV2.builder()
        .indexName("multi-attribute-gsi2")
        .partitionKeys(List.of(Attribute.builder().name("multi-attribute_pk1").type(AttributeType.STRING).build(), Attribute.builder().name("multi-attribute_pk2").type(AttributeType.NUMBER).build()))
        .sortKey(Attribute.builder().name("sk").type(AttributeType.STRING).build())
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var table = new TableV2(this, "Table", new TablePropsV2 {
    PartitionKey = new Attribute { Name = "pk", Type = AttributeType.STRING },
    GlobalSecondaryIndexes = new [] { new GlobalSecondaryIndexPropsV2 {
        IndexName = "gsi1",
        PartitionKey = new Attribute { Name = "pk", Type = AttributeType.STRING }
    } }
});

table.AddGlobalSecondaryIndex(new GlobalSecondaryIndexPropsV2 {
    IndexName = "gsi2",
    PartitionKey = new Attribute { Name = "pk", Type = AttributeType.STRING }
});

// Add a GSI with multi-attribute keys
table.AddGlobalSecondaryIndex(new GlobalSecondaryIndexPropsV2 {
    IndexName = "multi-attribute-gsi2",
    PartitionKeys = new [] { new Attribute { Name = "multi-attribute_pk1", Type = AttributeType.STRING }, new Attribute { Name = "multi-attribute_pk2", Type = AttributeType.NUMBER } },
    SortKey = new Attribute { Name = "sk", Type = AttributeType.STRING }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
table := dynamodb.NewTableV2(this, jsii.String("Table"), &TablePropsV2{
	PartitionKey: &Attribute{
		Name: jsii.String("pk"),
		Type: dynamodb.AttributeType_STRING,
	},
	GlobalSecondaryIndexes: []GlobalSecondaryIndexPropsV2{
		&GlobalSecondaryIndexPropsV2{
			IndexName: jsii.String("gsi1"),
			PartitionKey: &Attribute{
				Name: jsii.String("pk"),
				Type: dynamodb.AttributeType_STRING,
			},
		},
	},
})

table.AddGlobalSecondaryIndex(&GlobalSecondaryIndexPropsV2{
	IndexName: jsii.String("gsi2"),
	PartitionKey: &Attribute{
		Name: jsii.String("pk"),
		Type: dynamodb.AttributeType_STRING,
	},
})

// Add a GSI with multi-attribute keys
table.AddGlobalSecondaryIndex(&GlobalSecondaryIndexPropsV2{
	IndexName: jsii.String("multi-attribute-gsi2"),
	PartitionKeys: []Attribute{
		&Attribute{
			Name: jsii.String("multi-attribute_pk1"),
			Type: dynamodb.AttributeType_STRING,
		},
		&Attribute{
			Name: jsii.String("multi-attribute_pk2"),
			Type: dynamodb.AttributeType_NUMBER,
		},
	},
	SortKey: &Attribute{
		Name: jsii.String("sk"),
		Type: dynamodb.AttributeType_STRING,
	},
})
```

## Properties

- `indexName`: string (required) — The name of the secondary index.

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

  **Default:** inherited from the primary table.

  Note: This can only be configured if the primary table billing is PAY_PER_REQUEST.

- `maxWriteRequestUnits`: number — The maximum write request units.

  **Default:** inherited from the primary table.

  Note: This can only be configured if the primary table billing is PAY_PER_REQUEST.

- `nonKeyAttributes`: string[] — The non-key attributes that are projected into the secondary index.

  **Default:** No additional attributes

- `partitionKey`: [Attribute](https://docs.aws.amazon.com/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).

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

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

  If a single field forms the partition key, you can use either
  `partitionKey` or `partitionKeys` to specify the partition key. Exactly
  one of these must be specified.

  You must use `partitionKeys` field if the partition key is a multi-attribute key
  (consists of multiple fields).

  NOTE: although the name of this field makes it sound like it creates
  multiple keys, it does not. It defines a single key that consists of
  of multiple fields.

  The order of fields is not important.

- `projectionType`: [ProjectionType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.ProjectionType.html) = ALL — The set of attributes that are projected into the secondary index.

- `readCapacity`: [Capacity](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Capacity.html) — The read capacity.

  **Default:** inherited from the primary table.

  Note: This can only be configured if the primary table billing is provisioned.

- `sortKey`: [Attribute](https://docs.aws.amazon.com/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).

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

  **Default:** no sort key

  If a single field forms the sort key, you can use either
  `sortKey` or `sortKeys` to specify the sort key. At most one of these
  may be specified.

  You must use `sortKeys` field if the sort key is a multi-attribute key
  (consists of multiple fields).

  NOTE: although the name of this field makes it sound like it creates
  multiple keys, it does not. It defines a single key that consists of
  of multiple fields at the same time.

  NOTE: The order of fields is important!

- `warmThroughput`: [WarmThroughput](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.WarmThroughput.html) — The warm throughput configuration for the global secondary index.

  **Default:** no warm throughput is configured

- `writeCapacity`: [Capacity](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Capacity.html) — The write capacity.

  **Default:** inherited from the primary table.

  Note: This can only be configured if the primary table billing is provisioned.
