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?
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" {
...
}
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)
count example:
resource "aws_dynamodb_table_item" "items" {
count = 4
item <<EOF
{
"pk": {"S": "${count.index}"}
}
EOF
for_each example:
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With