首页 > 解决方案 > AWS Amplify 在创建 DynamoDB 表后创建全局二级索引

问题描述

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

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

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

这工作正常。现在我的数据量在稳步增长,我需要能够查询结果并对其进行排序。

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

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

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

跑步

amplify push --minify

我收到错误

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.

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

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

任何想法如何进行?

提前致谢!

问候克里斯蒂安

标签: amazon-web-servicesgraphqlamazon-dynamodbaws-amplify

解决方案


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

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


推荐阅读