/// <summary>
/// Creates all samples defined in SampleTables map
/// </summary>
/// <param name="client"></param>
public static void CreateSampleTables(AmazonDynamoDBClient client)
{
Console.WriteLine("Getting list of tables");
List<string> currentTables = client.ListTables().TableNames;
Console.WriteLine("Number of tables: " + currentTables.Count);
bool tablesAdded = false;
if (!currentTables.Contains("Businesses"))
{
Console.WriteLine("Table Businesses does not exist, creating");
client.CreateTable(new CreateTableRequest
{
TableName = "Businesses",
ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 3, WriteCapacityUnits = 1 },
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement
{
AttributeName = "Name",
KeyType = KeyType.HASH
},
new KeySchemaElement
{
AttributeName = "Id",
KeyType = KeyType.RANGE
}
},
AttributeDefinitions = new List<AttributeDefinition>
{
new AttributeDefinition { AttributeName = "Name", AttributeType = ScalarAttributeType.S },
new AttributeDefinition { AttributeName = "Id", AttributeType = ScalarAttributeType.N }
}
});
tablesAdded = true;
}
if (tablesAdded)
{
bool allActive;
do
{
allActive = true;
Console.WriteLine("While tables are still being created, sleeping for 5 seconds...");
Thread.Sleep(TimeSpan.FromSeconds(5));
foreach (var tableName in SAMPLE_TABLE_NAMES)
{
string tableStatus = GetTableStatus(client, tableName);
bool isTableActive = string.Equals(tableStatus, "ACTIVE", StringComparison.OrdinalIgnoreCase);
if (!isTableActive)
allActive = false;
}
} while (!allActive);
}
Console.WriteLine("All sample tables created");
}