Skip to content
v2.277.0

GlobalSecondaryIndexPropsV2 Struct ​

Properties used to configure a global secondary index.

Example ​

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

indexNamestringindex_namestrindexNameStringIndexNamestringIndexName*stringrequired#
The name of the secondary index.
maxReadRequestUnitsoptionalnumbermax_read_request_unitsoptionalint | floatmaxReadRequestUnitsoptionalNumberMaxReadRequestUnitsoptionaldoubleMaxReadRequestUnitsoptional*float64#
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.

maxWriteRequestUnitsoptionalnumbermax_write_request_unitsoptionalint | floatmaxWriteRequestUnitsoptionalNumberMaxWriteRequestUnitsoptionaldoubleMaxWriteRequestUnitsoptional*float64#
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.

nonKeyAttributesoptionalstring[]non_key_attributesoptionaltyping.List[str]nonKeyAttributesoptionalList<String>NonKeyAttributesoptionalstring[]NonKeyAttributesoptional*[]*string#
The non-key attributes that are projected into the secondary index.

Default: No additional attributes

partitionKeyoptionalAttributepartition_keyoptionalAttributepartitionKeyoptionalAttributePartitionKeyoptionalAttributePartitionKeyoptionalAttribute#
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).

partitionKeysoptionalAttribute[]partition_keysoptionaltyping.List[Attribute]partitionKeysoptionalList<Attribute>PartitionKeysoptionalAttribute[]PartitionKeysoptional*[]Attribute#
Multi-attribute partition key.

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

notes

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.

projectionTypeoptionalProjectionTypeprojection_typeoptionalProjectionTypeprojectionTypeoptionalProjectionTypeProjectionTypeoptionalProjectionTypeProjectionTypeoptionalProjectionType= ALL#
The set of attributes that are projected into the secondary index.
readCapacityoptionalCapacityread_capacityoptionalCapacityreadCapacityoptionalCapacityReadCapacityoptionalCapacityReadCapacityoptionalCapacity#
The read capacity.

Default: inherited from the primary table.

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

sortKeyoptionalAttributesort_keyoptionalAttributesortKeyoptionalAttributeSortKeyoptionalAttributeSortKeyoptionalAttribute#
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).

sortKeysoptionalAttribute[]sort_keysoptionaltyping.List[Attribute]sortKeysoptionalList<Attribute>SortKeysoptionalAttribute[]SortKeysoptional*[]Attribute#
Multi-attribute sort key.

Default: no sort key

notes

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!

warmThroughputoptionalWarmThroughputwarm_throughputoptionalWarmThroughputwarmThroughputoptionalWarmThroughputWarmThroughputoptionalWarmThroughputWarmThroughputoptionalWarmThroughput#
The warm throughput configuration for the global secondary index.

Default: no warm throughput is configured

writeCapacityoptionalCapacitywrite_capacityoptionalCapacitywriteCapacityoptionalCapacityWriteCapacityoptionalCapacityWriteCapacityoptionalCapacity#
The write capacity.

Default: inherited from the primary table.

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