# LocalSecondaryIndexProps

Properties for a local secondary index.

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

- 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#L353)

## Example

TypeScript:

```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:

```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:

```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());
```

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 },
    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 }
});
```

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,
	},
	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

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

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

  **Default:** No additional attributes

- `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.

- `sortKey`: [Attribute](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Attribute.html) (required) — The attribute of a sort key for the local secondary index.
