private async Task WaitTillTableDeletedAsync(string tableName, DeleteTableResponse response) { var tableDescription = response.TableDescription; string status = tableDescription.TableStatus; // Wait until table is created. Call DescribeTable try { while (status == "DELETING") { System.Threading.Thread.Sleep(5000); var res = await _dynamoDbClient.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); status = res.Table.TableStatus; } } catch (ResourceNotFoundException) { // Table deleted } }
private async Task EnsureTable() { try { var poll = await _client.DescribeTableAsync(_tableName); } catch (ResourceNotFoundException) { await CreateTable(); } }
private async Task EnsureTable(string tableName, Func <Task> createTask) { try { await _client.DescribeTableAsync(tableName); } catch (ResourceNotFoundException) { _logger.LogWarning($"Provisioning DynamoDb table - {tableName}"); await createTask(); } }
//private static async Task<TableDescription> BuildOrDescribeTable() private static TableDescription BuildOrDescribeTable() { // Define the cancellation token. CancellationTokenSource source = new CancellationTokenSource(); CancellationToken token = source.Token; // build the widget table var request = new CreateTableRequest( tableName: "Widgets", keySchema: new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "WidgetId", KeyType = KeyType.HASH } }, attributeDefinitions: new List <AttributeDefinition> { new AttributeDefinition() { AttributeName = "WidgetId", AttributeType = ScalarAttributeType.S } }, provisionedThroughput: new ProvisionedThroughput { ReadCapacityUnits = 1, WriteCapacityUnits = 1 } ); Console.WriteLine("Sending request to build Widgets table..."); try { //var result = await dynamoclient.CreateTableAsync(request); var result = dynamoclient.CreateTableAsync(request).Result; Console.WriteLine("Table created."); return(result.TableDescription); } //catch (ResourceInUseException) catch (Exception e) { if (e.Message.Contains("Table already exists")) { // Table already created, just describe it Console.WriteLine("Table already exists. Fetching description..."); } return /*await*/ (dynamoclient.DescribeTableAsync(new DescribeTableRequest("Widgets"), token).Result.Table); } }
public static async Task WaitTillTableDeleted(AmazonDynamoDBClient client, string tableName, DeleteTableResponse response) { var tableDescription = response.TableDescription; string status = tableDescription.TableStatus; Console.WriteLine("Waiting for delete - " + tableName + " : " + status); // Let us wait until table is created. Call DescribeTable try { while (status == "DELETING") { System.Threading.Thread.Sleep(5000); // wait 5 seconds var res = await client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } } catch (ResourceNotFoundException exRnf) { for (Exception ex = exRnf; ex != null; ex = ex.InnerException) { Debug.WriteLine(ex.GetType().Name + " - " + ex.Message); } } }
private void GetTableDetails(AmazonDynamoDBClient client) { resultText.text += ("\n*** Retrieving table information ***\n"); var request = new DescribeTableRequest { TableName = @"speedmath_scores" }; client.DescribeTableAsync(request, (result) => { if (result.Exception != null) { resultText.text += result.Exception.Message; Debug.Log(result.Exception); return; } var response = result.Response; TableDescription description = response.Table; resultText.text += ("Name: " + description.TableName + "\n"); resultText.text += ("# of items: " + description.ItemCount + "\n"); resultText.text += ("Provision Throughput (reads/sec): " + description.ProvisionedThroughput.ReadCapacityUnits + "\n"); resultText.text += ("Provision Throughput (reads/sec): " + description.ProvisionedThroughput.WriteCapacityUnits + "\n"); }, null); }
public async Task <string> Add(AdvertModel model) { AdvertDbModel dbModel = _mapper.Map <AdvertDbModel>(model); dbModel.Id = Guid.NewGuid().ToString(); dbModel.CreationDateTime = DateTime.UtcNow; dbModel.Status = AdvertStatus.Pending; using (AmazonDynamoDBClient client = new AmazonDynamoDBClient()) { DescribeTableResponse table = await client.DescribeTableAsync("Adverts"); bool tableStatus = string.Compare(table.Table.TableStatus, "active", true) == 0; if (tableStatus) { using (DynamoDBContext context = new DynamoDBContext(client)) { await context.SaveAsync(dbModel); } } } return(dbModel.Id); }
private static async void WaitUntilTableDeleted(AmazonDynamoDBClient client, string tableName) { string status; // Let us wait until table is deleted. Call DescribeTable. do { System.Threading.Thread.Sleep(5000); // Wait 5 seconds. try { var res = await client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } catch (ResourceNotFoundException) { Console.WriteLine("Table name: {0} is not found. It is deleted", tableName); return; } } while (status == "DELETING"); }
public void TestCache() { Func <string, TableDescription> creator = tn => client.DescribeTableAsync(tn).Result.Table; var tableName = GetTableName(); var tableCache = SdkCache.GetCache <string, TableDescription>(client, DynamoDBTests.TableCacheIdentifier, StringComparer.Ordinal); Assert.AreEqual(0, tableCache.ItemCount); using (var counter = new ServiceResponseCounter(client)) { var table = tableCache.GetValue(tableName, creator); Assert.AreEqual(1, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); // verify the item is still there table = tableCache.GetValue(tableName, creator); Assert.AreEqual(1, counter.ResponseCount); // verify item was reloaded tableCache.Clear(tableName); table = tableCache.GetValue(tableName, creator); Assert.AreEqual(2, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); // test item expiration tableCache.MaximumItemLifespan = TimeSpan.FromSeconds(1); UtilityMethods.Sleep(tableCache.MaximumItemLifespan); table = tableCache.GetValue(tableName, creator); Assert.AreEqual(3, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); } }
private async Task WaitUntilTableReady() { string status = null; do { System.Threading.Thread.Sleep(5000); // Wait 5 seconds. try { DescribeTableResponse res = await client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } catch (ResourceNotFoundException ex) { Console.WriteLine(ex); } } while (status != "ACTIVE"); }
// Use this for initialization void Start() { // Load all sprites in the Kenney.nl resource folder. allSprites = Resources.LoadAll <Sprite>("Kenney.nl"); selectedHair = selectedHairImage.overrideSprite.name; selectedFace = selectedFaceImage.overrideSprite.name; selectedBody = selectedBodyImage.overrideSprite.name; selectedShirt = selectedShirtImage.overrideSprite.name; selectedPants = selectedPantsImage.overrideSprite.name; selectedShoes = selectedShoesImage.overrideSprite.name; // Setup our credentials which will use our Cognito identity pool to hand us short-term session credentials, // giving us access to what we have provided access to with our IAM role policies, in this case, access to our // DynamoDB table. credentials = new CognitoAWSCredentials(cognitoIdentityPoolString, RegionEndpoint.USEast1); credentials.GetIdentityIdAsync(delegate(AmazonCognitoIdentityResult <string> result) { if (result.Exception != null) { Debug.LogError("exception hit: " + result.Exception.Message); } // Create a DynamoDB client, passing in our credentials from Cognito. var ddbClient = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1); resultText.text += ("\n*** Retrieving table information ***\n"); // Create a DescribeTableRequest to get information about our table, and ensure we can access it. var request = new DescribeTableRequest { TableName = @"CharacterCreator" }; ddbClient.DescribeTableAsync(request, (ddbresult) => { if (result.Exception != null) { resultText.text += result.Exception.Message; Debug.Log(result.Exception); return; } var response = ddbresult.Response; // Debug information TableDescription description = response.Table; resultText.text += ("Name: " + description.TableName + "\n"); resultText.text += ("# of items: " + description.ItemCount + "\n"); resultText.text += ("Provision Throughput (reads/sec): " + description.ProvisionedThroughput.ReadCapacityUnits + "\n"); resultText.text += ("Provision Throughput (reads/sec): " + description.ProvisionedThroughput.WriteCapacityUnits + "\n"); }, null); // Set our _client field to the dynamoDB client. _client = ddbClient; // Fetch any stored characters from the DB FetchAllCharactersFromAWS(); }); }
private async void initDbTables() { var client = new AmazonDynamoDBClient(RegionEndpoint.USWest1); var status = ""; do { // Wait 5 seconds before checking (again). System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); try { var response = await client.DescribeTableAsync(new DescribeTableRequest { TableName = "Rewards" }); Debug.WriteLine("Table = {0}, Status = {1}", response.Table.TableName, response.Table.TableStatus); status = response.Table.TableStatus; } catch (ResourceNotFoundException) { // DescribeTable is eventually consistent. So you might // get resource not found. } } while (status != TableStatus.ACTIVE); }
private async Task WaitTillTableDeletedAsync(AmazonDynamoDBClient client, string tableName, DeleteTableResponse response) { var tableDescription = response.TableDescription; string status = tableDescription.TableStatus; Console.WriteLine(tableName + " - " + status); // Let us wait until table is created. Call DescribeTable try { while (status == "DELETING") { await Task.Delay(5000); // wait 5 seconds var res = await client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } } catch (ResourceNotFoundException) { // Table deleted. } }
private async Task WaitTillTableCreatedAsync(AmazonDynamoDBClient client, string tableName, CreateTableResponse response = null) { string status = "NOTACTIVE"; if (response != null) { var tableDescription = response.TableDescription; status = tableDescription.TableStatus; } Console.WriteLine(tableName + " - " + status); // Let us wait until table is created. Call DescribeTable. while (status != "ACTIVE") { await Task.Delay(5000); try { var res = await client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } // Try-catch to handle potential eventual-consistency issue. catch (ResourceNotFoundException) { } } }
private bool LockTableExists() { try { DescribeTableResponse result = _client.DescribeTableAsync(new DescribeTableRequest(_tableName)) .Result; if (result.HttpStatusCode != HttpStatusCode.OK) { return(false); } var tableActiveOrUpdated = _availableTableStatuses.Contains(result.Table.TableStatus); return(tableActiveOrUpdated); } catch (ResourceNotFoundException) { return(false); } catch (Exception) { return(false); } }
private static void WaitUntilTableReady(AmazonDynamoDBClient client, string tableName, CancellationToken cancel) { string status = null; // Let us wait until table is created. Call DescribeTable. do { System.Threading.Thread.Sleep(5000); // Wait 5 seconds. try { var res = client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }, cancel).Result; Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } catch (ResourceNotFoundException) { // DescribeTable is eventually consistent. So you might // get resource not found. So we handle the potential exception. } } while (status != "ACTIVE"); }
public static async Task WaitTillTableCreated(AmazonDynamoDBClient client, string tableName, CreateTableResponse response) { var tableDescription = response.TableDescription; string status = tableDescription.TableStatus; Console.WriteLine(tableName + " - " + status); // Let us wait until table is created. Call DescribeTable. while (status != "ACTIVE") { System.Threading.Thread.Sleep(5000); // Wait 5 seconds. try { var res = await client.DescribeTableAsync(new DescribeTableRequest { TableName = tableName }); Console.WriteLine("Table name: {0}, status: {1}", res.Table.TableName, res.Table.TableStatus); status = res.Table.TableStatus; } // Try-catch to handle potential eventual-consistency issue. catch (ResourceNotFoundException exRnf) { for (Exception ex = exRnf; ex != null; ex = ex.InnerException) { Debug.WriteLine(ex.GetType().Name + " - " + ex.Message); } } } }
public async Task <bool> CheckHealthAsync() { using var client = new AmazonDynamoDBClient(); var tableData = await client.DescribeTableAsync("Adverts"); return(string.Compare(tableData.Table.TableStatus, "active", StringComparison.OrdinalIgnoreCase) == 0); }
public async Task <string> AddAsync(AdvertModel model) { var dbModel = _mapper.Map <AdvertDbModel>(model); dbModel.Id = Guid.NewGuid().ToString(); dbModel.CreationDateTime = DateTime.UtcNow; dbModel.Status = AdvertStatus.Pending; try { using (var client = new AmazonDynamoDBClient()) { var table = await client.DescribeTableAsync("Advert"); using (var context = new DynamoDBContext(client)) { await context.SaveAsync(dbModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(dbModel.Id); }
private async Task EnsureProvisionedAsync(CancellationToken token) { try { await _client.DescribeTableAsync(TableName, token); } catch (ResourceNotFoundException) { // TODO: Log // Default table information for the Ubisoft key table var table = new CreateTableRequest( TableName, new List <KeySchemaElement> { new KeySchemaElement("id", KeyType.HASH) }, new List <AttributeDefinition> { new AttributeDefinition("id", ScalarAttributeType.S) }, new ProvisionedThroughput(5, 5) ); await _client.CreateTableAsync(table, token); // Wait for the table to finish being created await Task.Delay(5000, token); } }
public async Task <bool> CheckHealthAsync() { using var client = new AmazonDynamoDBClient(); var tableData = await client.DescribeTableAsync("Adverts"); return(tableData.Table.TableStatus.Value.Equals("active", StringComparison.InvariantCultureIgnoreCase)); }
public async Task <bool> CheckHealthAsync() { using var client = new AmazonDynamoDBClient(); using var context = new DynamoDBContext(client); var tableData = await client.DescribeTableAsync("Adverts"); return(string.Compare(tableData.Table.TableStatus, "active", true) == 0); }
private async Task <bool> IsTableActive(AmazonDynamoDBClient client, DynamoDBContext context) { var tableData = await client.DescribeTableAsync(_tableName); var tableStatus = tableData.Table.TableStatus.Value.ToLower(); return(tableStatus == "active"); }
private async Task <long> GetItemsCount(string tableName, AmazonDynamoDBClient client) { var request = new DescribeTableRequest(tableName); var response = await client.DescribeTableAsync(request).ConfigureAwait(false); return(response.Table.ItemCount); }
public bool CheckHealthAsync() { using (var client = new AmazonDynamoDBClient()) { var tableData = client.DescribeTableAsync("Adverts").Result; return(string.Compare(tableData.Table.TableStatus.Value, "active", StringComparison.OrdinalIgnoreCase) == 0); } }
public async Task <bool> CheckHealthAsync() { using (var client = new AmazonDynamoDBClient()) { var status = await client.DescribeTableAsync("Adverts"); return(status.Table.TableStatus == TableStatus.ACTIVE); } }
/// <summary> /// GetTableDescriptionAsync will get a Table's description from DynamoDb /// </summary> /// <param name="tableName"></param> /// <returns>A Task of type DescribeTableResponse</returns> public virtual async Task <DescribeTableResponse> GetTableDescriptionAsync(string tableName) { var request = new DescribeTableRequest { TableName = tableName }; return(await _client.DescribeTableAsync(request).ConfigureAwait(false)); }
private async Task <TableStatus> GetTableStatusAsync() { DescribeTableResponse response = await _dynamoDbClient.DescribeTableAsync(new DescribeTableRequest { TableName = _tableName }); return(response.Table.TableStatus); }
private async Task <int> getTableCount(string table) { DescribeTableResponse description = await _client.DescribeTableAsync(table); // The reason for the 2, at the start I only inserted 2 records and // since Dynamodb takes 6 hours to update the item count, // so it is useful for the first 6 hours of production and that is it. return(description.Table.ItemCount == 0 ? 2 : (int)description.Table.ItemCount); }
public async Task<bool> CheckHealthAsync() { Console.WriteLine("Health checking..."); using (var client = new AmazonDynamoDBClient()) { var tableData = await client.DescribeTableAsync("Adverts"); return string.Compare(tableData.Table.TableStatus, "active", true) == 0; } }