AWS Amplify 在创建 DynamoDB 表后创建全局二级索引

use*_*121 5 amazon-web-services amazon-dynamodb graphql aws-amplify

我有一个包含约 70 个表的大型架构,其中许多表相互连接(194 个 @connection 指令),如下所示:

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

type table2 @model {
  id:ID!
  ....
}
Run Code Online (Sandbox Code Playgroud)

这很好用。现在我的数据量正在稳步增长,我需要能够查询结果并对它们进行排序。

我读过几篇文章,发现其中一篇建议我创建一个 @key 指令来生成具有 2 个字段的 GSI,这样我就可以说“根据我的过滤器属性过滤结果,按字段“名称”对它们进行排序并返回前 10 个条目,其余可通过 nextToken 参数访问”

所以我尝试添加一个像这样的GSI:

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

跑步

amplify push --minify
Run Code Online (Sandbox Code Playgroud)

我收到错误

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.
Run Code Online (Sandbox Code Playgroud)

为什么它创建LSI而不是GSI?在创建和填充表后,是否有任何方法可以将 @key 指令添加到表中?来自不同表的数据集如此之多,彼此链接,因此仅设置一个新模式就需要很长时间。

如果这有一些影响的话,计费模式是 PAY_PER_REQUEST。

有什么想法如何继续吗?

提前致谢!

问候克里斯蒂安

Xin*_*Xin 1

如果您使用新环境,请先删除文件夹#current-cloud-backend。

然后amplify init再次创建该文件夹,可惜其中只有一个文件 amplify-meta.json。