haohaolee
haohaolee

Reputation: 707

What is the maximum number non-key attributes of Global Secondary Index (GSI) in DynamoDB?

According to the AWS doc, we can have at most 20 non-key attributes in local secondary index (LSI) in DynamoDB, but how about global secondary index?

The issue we encountered is we want to include more than 20 non-key attributes in GSI, but we could not find a way or a doc to explain this. The only option we have is to use ALL to include all non-key attributes which leads to huge storage cost.

Thanks

Upvotes: 1

Views: 1079

Answers (1)

Maurice
Maurice

Reputation: 13117

The docs specify the limit for the Projection.NonKeyAttributes field that's used for the Global and Local secondary indexes:

NonKeyAttributes

Represents the non-key attribute names which will be projected into the index.

For local secondary indexes, the total count of NonKeyAttributes summed across all of the local secondary indexes, must not exceed 20. If you project the same attribute into two different indexes, this counts as two distinct attributes when determining the total.

Type: Array of strings

Array Members: Minimum number of 1 item. Maximum number of 20 items.

Length Constraints: Minimum length of 1. Maximum length of 255.

Required: No

This is not something that can be adjusted.

A Workaround may be to change your data structure - do you need flat data structures? You could also group some attributes together in a map:

{
  "id": 123,
  "address": {
    "city": "Berlin",
    "street": "Straße des 17. Juni",
    "number": "17",
  }
}
// instead of 
{
  "id": 123,
  "city": "Berlin",
  "street": "Straße des 17. Juni",
  "number": "17"
}

Upvotes: 1

Related Questions