本文介绍了通过 terraform 添加多个 DynamoDB 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在dynamoDB表中添加多个项目?
How to add multiple items in dynamoDB table?
table_name = "${var.environment}-kaleidos-dynamodb-MappingConfig"
hash_key = "eventType"
item = <<EOF
json
EOF
}````
DynamoDB always expects one item. Is there a way to provide multiple items?
推荐答案
无法使用单个资源aws_dynamodb_table_item"
添加多个项目.你可以在同一个文件中有多个resource
语句,只要你给它们起不同的名字,例如:
There's no way to add multiple items using a single resource "aws_dynamodb_table_item"
. You can have multiple resource
statements in the same file, as long as you give them different names, for example:
resource "aws_dynamodb_table_item" "item1" {
...
}
resource "aws_dynamodb_table_item" "item2" {
...
}
如果您尝试基于数组或地图或特定数字创建项目,您可以使用 count
或 for_each
(for_each
在 0.12.6 中引入)
If you are trying to create items based on an array or map or a specific number, you can use count
or for_each
(for_each
was introduced in 0.12.6)
计数
示例:
resource "aws_dynamodb_table_item" "items" {
count = 4
item <<EOF
{
"pk": {"S": "${count.index}"}
}
EOF
for_each
示例:
resource "aws_dynamodb_table_item" "items" {
for_each = {
item1 = {
something = "hello"
}
item2 = {
something = "hello2"
}
}
item = <<EOF
{
"pk": {"S": "${each.key}"},
"something": {"S": "${each.value.something}"}
}
EOF
}
这篇关于通过 terraform 添加多个 DynamoDB 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!