Skip to content
v2.278.0

LocalSecondaryIndexProps Struct ​

Properties for a local secondary index.

Example ​

ts
const table = new dynamodb.TableV2(this, 'Table', {
  partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
  sortKey: { name: 'sk', type: dynamodb.AttributeType.NUMBER },
  localSecondaryIndexes: [
    {
      indexName: 'lsi1',
      sortKey: { name: 'sk', type: dynamodb.AttributeType.NUMBER },
    },
  ],
});

table.addLocalSecondaryIndex({
  indexName: 'lsi2',
  sortKey: { name: 'sk', type: dynamodb.AttributeType.NUMBER },
});
python
table = dynamodb.TableV2(self, "Table",
    partition_key=dynamodb.Attribute(name="pk", type=dynamodb.AttributeType.STRING),
    sort_key=dynamodb.Attribute(name="sk", type=dynamodb.AttributeType.NUMBER),
    local_secondary_indexes=[dynamodb.LocalSecondaryIndexProps(
        index_name="lsi1",
        sort_key=dynamodb.Attribute(name="sk", type=dynamodb.AttributeType.NUMBER)
    )
    ]
)

table.add_local_secondary_index(
    index_name="lsi2",
    sort_key=dynamodb.Attribute(name="sk", type=dynamodb.AttributeType.NUMBER)
)
java
TableV2 table = TableV2.Builder.create(this, "Table")
        .partitionKey(Attribute.builder().name("pk").type(AttributeType.STRING).build())
        .sortKey(Attribute.builder().name("sk").type(AttributeType.NUMBER).build())
        .localSecondaryIndexes(List.of(LocalSecondaryIndexProps.builder()
                .indexName("lsi1")
                .sortKey(Attribute.builder().name("sk").type(AttributeType.NUMBER).build())
                .build()))
        .build();

table.addLocalSecondaryIndex(LocalSecondaryIndexProps.builder()
        .indexName("lsi2")
        .sortKey(Attribute.builder().name("sk").type(AttributeType.NUMBER).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 },
    SortKey = new Attribute { Name = "sk", Type = AttributeType.NUMBER },
    LocalSecondaryIndexes = new [] { new LocalSecondaryIndexProps {
        IndexName = "lsi1",
        SortKey = new Attribute { Name = "sk", Type = AttributeType.NUMBER }
    } }
});

table.AddLocalSecondaryIndex(new LocalSecondaryIndexProps {
    IndexName = "lsi2",
    SortKey = new Attribute { Name = "sk", Type = AttributeType.NUMBER }
});
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,
	},
	SortKey: &Attribute{
		Name: jsii.String("sk"),
		Type: dynamodb.AttributeType_NUMBER,
	},
	LocalSecondaryIndexes: []LocalSecondaryIndexProps{
		&LocalSecondaryIndexProps{
			IndexName: jsii.String("lsi1"),
			SortKey: &Attribute{
				Name: jsii.String("sk"),
				Type: dynamodb.AttributeType_NUMBER,
			},
		},
	},
})

table.AddLocalSecondaryIndex(&LocalSecondaryIndexProps{
	IndexName: jsii.String("lsi2"),
	SortKey: &Attribute{
		Name: jsii.String("sk"),
		Type: dynamodb.AttributeType_NUMBER,
	},
})

Properties ​

indexNamestringindex_namestrindexNameStringIndexNamestringIndexName*string required #
The name of the secondary index.
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

projectionTypeoptionalProjectionTypeprojection_typeoptionalProjectionTypeprojectionTypeoptionalProjectionTypeProjectionTypeoptionalProjectionTypeProjectionTypeoptionalProjectionType = ALL #
The set of attributes that are projected into the secondary index.
sortKeyAttributesort_keyAttributesortKeyAttributeSortKeyAttributeSortKeyAttribute required #
The attribute of a sort key for the local secondary index.