private String enableStreamForTable(AmazonDynamoDBClient client, StreamViewType viewType, String tableName) { DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(tableName); DescribeTableResult describeResult = client.describeTable(describeTableRequest); if (describeResult.getTable().getStreamSpecification().isStreamEnabled()) { //TODO: what if the viewtype doesn't match return describeResult.getTable().getLatestStreamId(); } StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(viewType); UpdateTableRequest updateTableRequest = new UpdateTableRequest() .withTableName(tableName) .withStreamSpecification(streamSpecification); UpdateTableResult result = client.updateTable(updateTableRequest); return result.getTableDescription().getLatestStreamId(); }
public static String enableStreamForTable(AmazonDynamoDBClient client, StreamViewType viewType, String tableName) { DescribeTableRequest describeTableRequest = new DescribeTableRequest() .withTableName(tableName); DescribeTableResult describeResult = client.describeTable(describeTableRequest); if (describeResult.getTable().getStreamSpecification().isStreamEnabled()) { //TODO: what if the viewtype doesn't match return describeResult.getTable().getLatestStreamId(); } StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(viewType); UpdateTableRequest updateTableRequest = new UpdateTableRequest() .withTableName(tableName) .withStreamSpecification(streamSpecification); UpdateTableResult result = client.updateTable(updateTableRequest); return result.getTableDescription().getLatestStreamId(); }
@Test public void test_updateTable() throws Exception { createTable(); DescribeTableResult describeResult = dynamoDb.describeTable(TEST_TABLE_NAME); Long readUnits = describeResult.getTable().getProvisionedThroughput().getReadCapacityUnits(); assertThat(readUnits, equalTo(UNITS)); UpdateTableResult updateResult = dynamoDb.updateTable(TEST_TABLE_NAME, new ProvisionedThroughput() .withReadCapacityUnits(new Long(200)) .withWriteCapacityUnits(new Long(200))); String tableName = updateResult.getTableDescription().getTableName(); assertThat(tableName, equalTo(TEST_TABLE_NAME)); ListTablesResult listResult = listTables(); describeResult = dynamoDb.describeTable(TEST_TABLE_NAME); readUnits = describeResult.getTable().getProvisionedThroughput().getReadCapacityUnits(); assertThat(readUnits, equalTo(new Long(200))); }
@Override public UpdateTableResult updateTable(UpdateTableRequest updateTableRequest) { this.updateTableRequest = updateTableRequest; return null; }