Kat*_*ych 16 amazon-dynamodb terraform
我想为DynamoDB表创建一个具有多个(> 10)属性的Terraform配置.我没有必要将所有属性添加为global_secondary_index或作为索引
local_secondary_index.但是当我运行terraform plan命令时,我有下一个错误:
All attributes must be indexed. Unused attributes: ...
我在validateDynamoDbTableAttributes函数中的Terraform存储库中找到了验证检查.
但据我所知,最佳做法是each table in DynamoDB is limited to a maximum of five global secondary indexes and five local secondary indexes来自DynamoDB中二级索引的一般指南.
由于我有超过10个属性,因此对我来说这似乎是一个问题.
我想了解为什么必须索引所有属性以及如果您拥有大量属性该怎么做.
谢谢!
Eri*_*son 24
你不是要定义每个属性你想创建表时使用的前面.
attribute里面块aws_dynamodb_table资源是不是确定哪些属性,你可以在你的应用程序中使用.他们正在定义表和索引的关键模式.
例如,以下Terraform定义了一个只包含哈希键的表:
resource "aws_dynamodb_table" "test" {
name = "test-table-name"
read_capacity = 10
write_capacity = 10
hash_key = "Attribute1"
attribute {
name = "Attribute1"
type = "S"
}
}
Run Code Online (Sandbox Code Playgroud)
此表中的每个项目都有Attribute1,但您可以使用您的应用程序创建其他属性

这意味着只要您不需要在一个属性中定义它们就可以拥有10个以上的属性AttributeDefinition,并且因为您说您不需要将它们编入索引,所以您会没事的.
有关混淆的一些讨论(attribute令人困惑且与DynamoDB API不匹配),请参阅此拉取请求.
我向 LSI 添加了一个投影字段,并为该投影字段添加了一个属性条目。这是导致错误的原因。您可以只在 non_key_attributes 中列出投影字段,如下所示,它不必定义为属性,因为它不是键:
local_secondary_index {
name = "allocated_plus_created-lsi"
range_key = "allocated_plus_created"
projection_type = "INCLUDE"
non_key_attributes = ["allocated"]
}
Run Code Online (Sandbox Code Playgroud)
分配不应定义为 TF 的属性。
| 归档时间: |
|
| 查看次数: |
5041 次 |
| 最近记录: |