AWS Amplify create Global Secondary Index after DynamoDB table creation

Viewed 1647

I have a large schema with ~70 tables and many of them connected to each other(194 @connection directives) like this:

type table1 @model {
  id:ID!
  name: String!
  ...
  table2: table2 @connection
}

type table2 @model {
  id:ID!
  ....
}

This works fine. Now my data amount is steadily growing and I need to be able to query for results and sort them.

I've read several articles and found one giving me the advice to create a @key directive to generate a GSI with 2 fields so I can say "Filter the results according to my filter property, sort them by the field "name" and return the first 10 entries, the rest accessible via nextToken parameter"

So I tried to add a GSI like this:

type table1 @model 
@key(name: "byName", fields:["id","name"], queryField:"idByName"){
  id:ID!
  name: String!
  ...
  table2: table2 @connection
}

running

amplify push --minify

I receive the error

Attempting to add a local secondary index to the table1Table table in the table1 stack. Local secondary indexes must be created when the table is created.
An error occured during the push operation: Attempting to add a local secondary index to the table1Table table in the table1 stack.
Local secondary indexes must be created when the table is created.

Why does it create a LSI instead of a GSI? Are there any ways to add @key directives to the tables after they have been created and filled? There are so many datasets from different tables linked with each other so just setting up a new schema would take ages.

Billingmode is PAY_PER_REQUEST if this has some impact.

Any ideas how to proceed?

Thanks in advance!

Regards Christian

1 Answers

If you are using new environment, delete folder #current-cloud-backend first.

Then amplify init created the folder again but alas, with only one file in it amplify-meta.json.

Related