I'm uisng updateTable of DynmaoDB and based on the documentation, if we want to create multiple Global Secondary Indexes (GSIs) we need to have multiple objects in "GlobalSecondaryIndexUpdates" field, so I'm passing the following params, but it does not update the GSIs; however if I'm just creating one GSI (passing one object in "GlobalSecondaryIndexUpdates" field, it works); here is the params I'm passing for creating multiple GSIs:
{
"TableName": "movies",
"AttributeDefinitions": [{
"AttributeName": "id",
"AttributeType": "N"
}, {
"AttributeName": "title",
"AttributeType": "S"
}, {
"AttributeName": "subtitle",
"AttributeType": "S"
}],
"GlobalSecondaryIndexUpdates": [{
"Create": {
"IndexName": "title",
"ProvisionedThroughput": {
"ReadCapacityUnits": "5",
"WriteCapacityUnits": "5"
},
"KeySchema": [{
"AttributeName": "title",
"KeyType": "HASH"
}],
"Projection": {
"ProjectionType": "ALL"
}
}
}, {
"Create": {
"IndexName": "subtitle",
"ProvisionedThroughput": {
"ReadCapacityUnits": "5",
"WriteCapacityUnits": "5"
},
"KeySchema": [{
"AttributeName": "subtitle",
"KeyType": "HASH"
}],
"Projection": {
"ProjectionType": "ALL"
}
}
}]
}
Am I passing the params in a wrong format?
From the DynamoDB documentation:
So the SDK now provides a
Table.createGSI
helper function for exactly this purpose. See a blog post on the topic.This helper returns an
Index
object and you can callindex.waitForActive();
to wait until the index has been built before building the next GSI which avoids this Exception.