Skip to content

Instantly share code, notes, and snippets.

@vladdima94
Created October 18, 2020 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladdima94/82079519b0ce3a90c7ded2a1c62a1776 to your computer and use it in GitHub Desktop.
Save vladdima94/82079519b0ce3a90c7ded2a1c62a1776 to your computer and use it in GitHub Desktop.
public class DynamoDBLocalStarterTest {
// ...
public static CreateTableResult createTable(
AmazonDynamoDB ddb, String tableName, String hashKeyName, String rangeKeyName) {
List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
attributeDefinitions.add(new AttributeDefinition(hashKeyName, ScalarAttributeType.S));
ks.add(new KeySchemaElement(hashKeyName, KeyType.HASH));
if(!Strings.isNullOrEmpty(rangeKeyName)) {
attributeDefinitions.add(new AttributeDefinition(rangeKeyName, ScalarAttributeType.S));
ks.add(new KeySchemaElement(rangeKeyName, KeyType.RANGE));
}
ProvisionedThroughput provisionedthroughput = new ProvisionedThroughput(1000L, 1000L);
CreateTableRequest request =
new CreateTableRequest()
.withTableName(tableName)
.withAttributeDefinitions(attributeDefinitions)
.withKeySchema(ks)
.withProvisionedThroughput(provisionedthroughput);
return ddb.createTable(request);
}
public static DeleteTableResult deleteTable(AmazonDynamoDB ddb, String tableName) {
return ddb.deleteTable(tableName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment