Amplify-cli: How to add local secondary Index for DynamoDB table with amplify-cli?

Created on 25 Jun 2019  路  3Comments  路  Source: aws-amplify/amplify-cli

Note: If your feature-request is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum

Is your feature request related to a problem? Please describe.
By adding @key(fields: [String!]!, name: String, queryField: String) directory in .graphql file, I can easily create a GSI for my dynamodb table. However, I couldn't find a way to create LSI through AMPLIFY.

Describe the solution you'd like
Give me the opinion to create either GSI or LSI

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

graphql-transformer question

Most helpful comment

The current key functionality does generate LSIs as well. To generate an LSI, you can create a secondary @key directive with multiple fields, where the first field is the same as the hash key in the primary @key directive.

using the @key directive, the first @key directive: @key(fields:["HASH", "RANGE"]) will change the table hash and range keys to "HASH" and "RANGE". A second @key directive like: @key(name:"X", fields:["HASH", "RANGE_2"], queryField: "fieldToReferenceForLSI"] will generate the LSI because the hash is the same as the primary hash key. If instead your second key directive had its first field as "HASH_2", a GSI will be created.

All 3 comments

The current key functionality does generate LSIs as well. To generate an LSI, you can create a secondary @key directive with multiple fields, where the first field is the same as the hash key in the primary @key directive.

using the @key directive, the first @key directive: @key(fields:["HASH", "RANGE"]) will change the table hash and range keys to "HASH" and "RANGE". A second @key directive like: @key(name:"X", fields:["HASH", "RANGE_2"], queryField: "fieldToReferenceForLSI"] will generate the LSI because the hash is the same as the primary hash key. If instead your second key directive had its first field as "HASH_2", a GSI will be created.

@RossWilliams thanks for answering the question, @YoudongMa would that be a full answer to your question?

If you've further questions, please feel free to reopen the issue.

This answered my question. Thank you

Was this page helpful?
0 / 5 - 0 ratings