简体   繁体   English

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

[英]AWS Amplify create Global Secondary Index after DynamoDB table creation

I have a large schema with ~70 tables and many of them connected to each other(194 @connection directives) like this:我有一个包含约 70 个表的大型架构,其中许多表相互连接(194 个@connection 指令),如下所示:

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

So I tried to add a GSI like this:所以我尝试添加这样的 GSI:

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?为什么它会创建 LSI 而不是 GSI? Are there any ways to add @key directives to the tables after they have been created and filled?在创建和填充表后,有什么方法可以将 @key 指令添加到表中? 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.如果这有一些影响,计费模式是 PAY_PER_REQUEST。

Any ideas how to proceed?任何想法如何进行?

Thanks in advance!提前致谢!

Regards Christian问候克里斯蒂安

If you are using new environment, delete folder #current-cloud-backend first.如果您使用的是新环境,请先删除文件夹 #current-cloud-backend。

Then amplify init created the folder again but alas, with only one file in it amplify-meta.json.然后amplify init再次创建了该文件夹,但可惜其中只有一个文件 amplify-meta.json。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM