Can any one let me know whether UpdateTableSpec can only update KeySchema attributes and is there any way to update/modify a table with non-keyschema attributes ? My scenario is : I created a table with composite key comprising of a primary ( #id attribute) and range key ( #Name attribute). Now I want to add a third attribute, Gender, which is not a part of keyschema. Is it possible ?
I am updating my DynamoDB table using the following code but it does not add the Gender attribute, although it successfully updates the provisioned attribute:
static void updateTable() {
System.out.println("Updating the table with new attributes ...");
Table table = dynamoDB.getTable(tableName);
UpdateTableSpec updateTableSpec = new UpdateTableSpec();
List<AttributeDefinition> attributeDefinitionList = updateTableSpec.getAttributeDefinitions();
if (null == attributeDefinitionList) {
attributeDefinitionList = new ArrayList<AttributeDefinition>();
}
attributeDefinitionList.add(new AttributeDefinition()
.withAttributeName("Gender")
.withAttributeType("S"));
updateTableSpec.withAttributeDefinitions(attributeDefinitionList)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(6L)
.withWriteCapacityUnits(7L));;
table.updateTable(updateTableSpec);
try {
table.waitForActive();
System.out.println("Table updated succesfully");
} catch (final Exception ex) {
System.out.println("Exception occurred while updating the table");
}
}