private static async Task ConnectToTableAsync() { var tableResponse = await AWSDBclient.ListTablesAsync(); //create new table if it's missing if (!tableResponse.TableNames.Contains(tableName)) { await CreateTableAsync(); } }
public static async Task <Grocery> GetItemsById(Guid guid) { List <ScanCondition> conditions = new List <ScanCondition> { new ScanCondition("Id", ScanOperator.Equal, guid) }; var tableResponse = await AWSDBclient.ListTablesAsync(); if (tableResponse.TableNames.Contains(tableName)) { var allDocs = await DBContext.ScanAsync <Grocery>(conditions).GetRemainingAsync(); var singleDoc = allDocs.SingleOrDefault(); return(singleDoc); } else { return(new Grocery()); } }
private async static Task CreateTableAsync() { //Table not found, creating table await AWSDBclient.CreateTableAsync(new CreateTableRequest { TableName = tableName, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 1, WriteCapacityUnits = 1 }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "Id", KeyType = KeyType.HASH } }, AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = "Id", AttributeType = ScalarAttributeType.S } }, }); bool isTableAvailable = false; while (!isTableAvailable) { //Waiting for table to be active... Thread.Sleep(5000); var tableStatus = await AWSDBclient.DescribeTableAsync(tableName); isTableAvailable = tableStatus.Table.TableStatus == TableStatus.ACTIVE; } }