Terraform + DynamoDB:所有属性都必须被索引
Terraform + DynamoDB: All attributes must be indexed
我想为 DynamoDB table 创建一个具有多个(> 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
来自 General Guidelines for Secondary Indexes in DynamoDB。
因为我有 10 多个属性,所以这对我来说似乎是个问题。
我想了解为什么必须对所有属性进行索引,以及如果您有大量属性该怎么办。
谢谢!
您 不必 在创建 table.
时必须预先定义要使用的每个属性
aws_dynamodb_table
资源中的 attribute
块 而不是 定义您可以在应用程序中使用的属性。他们是defining the key schema for the table and indexes。
例如,下面的 Terraform 定义了一个 table 只有一个散列键:
resource "aws_dynamodb_table" "test" {
name = "test-table-name"
read_capacity = 10
write_capacity = 10
hash_key = "Attribute1"
attribute {
name = "Attribute1"
type = "S"
}
}
此 table 中的每个项目都有 Attribute1
,但您可以使用您的应用程序创建其他属性
这意味着您可以拥有 10 多个属性,只要您不需要在 AttributeDefinition
中定义它们,并且既然您说不需要将它们编入索引,那么您会好的。
有关混淆的一些讨论(attribute
令人混淆并且与 DynamoDB API 不匹配),请参阅 this pull request。
我正在向 LSI 添加一个投影场,并为该投影场添加一个属性条目。这是导致错误的原因。您可以只在 non_key_attributes 中列出投影字段,如下所示,它不必定义为属性,因为它不是键:
local_secondary_index {
name = "allocated_plus_created-lsi"
range_key = "allocated_plus_created"
projection_type = "INCLUDE"
non_key_attributes = ["allocated"]
}
Allocated 不应定义为 TF 的属性。
我想为 DynamoDB table 创建一个具有多个(> 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
来自 General Guidelines for Secondary Indexes in DynamoDB。
因为我有 10 多个属性,所以这对我来说似乎是个问题。
我想了解为什么必须对所有属性进行索引,以及如果您有大量属性该怎么办。
谢谢!
您 不必 在创建 table.
时必须预先定义要使用的每个属性aws_dynamodb_table
资源中的 attribute
块 而不是 定义您可以在应用程序中使用的属性。他们是defining the key schema for the table and indexes。
例如,下面的 Terraform 定义了一个 table 只有一个散列键:
resource "aws_dynamodb_table" "test" {
name = "test-table-name"
read_capacity = 10
write_capacity = 10
hash_key = "Attribute1"
attribute {
name = "Attribute1"
type = "S"
}
}
此 table 中的每个项目都有 Attribute1
,但您可以使用您的应用程序创建其他属性
这意味着您可以拥有 10 多个属性,只要您不需要在 AttributeDefinition
中定义它们,并且既然您说不需要将它们编入索引,那么您会好的。
有关混淆的一些讨论(attribute
令人混淆并且与 DynamoDB API 不匹配),请参阅 this pull request。
我正在向 LSI 添加一个投影场,并为该投影场添加一个属性条目。这是导致错误的原因。您可以只在 non_key_attributes 中列出投影字段,如下所示,它不必定义为属性,因为它不是键:
local_secondary_index {
name = "allocated_plus_created-lsi"
range_key = "allocated_plus_created"
projection_type = "INCLUDE"
non_key_attributes = ["allocated"]
}
Allocated 不应定义为 TF 的属性。