public static ModificationResults ApplyModifications(PreparedModifications prepared_modifications, bool continue_on_error = true) { ModificationResults modification_results = new ModificationResults(); if (prepared_modifications.modified_throughputs.Any()) { var table_name_groups = prepared_modifications.modified_throughputs .Where(modified_throughput => modified_throughput.new_provisioned_throughput != null) .GroupBy(modified_throughput => modified_throughput.table_name) .ToList(); foreach (var table_name_group in table_name_groups) { try { UpdateTableRequest update_table_request = new UpdateTableRequest { TableName = table_name_group.Key }; update_table_request.ProvisionedThroughput = null; update_table_request.GlobalSecondaryIndexUpdates = new List <GlobalSecondaryIndexUpdate>(); ModifiedThroughput table_modified_throughput = table_name_group.SingleOrDefault(modified_throughput => string.IsNullOrEmpty(modified_throughput.index_name)); if (table_modified_throughput != null) { update_table_request.ProvisionedThroughput = table_modified_throughput.new_provisioned_throughput; } List <ModifiedThroughput> index_modified_throughputs = table_name_group.Where(modified_throughput => !string.IsNullOrEmpty(modified_throughput.index_name)).ToList(); foreach (var index_modified_throughput in index_modified_throughputs) { GlobalSecondaryIndexUpdate global_secondary_index_update = new GlobalSecondaryIndexUpdate { Update = new UpdateGlobalSecondaryIndexAction { IndexName = index_modified_throughput.index_name, ProvisionedThroughput = index_modified_throughput.new_provisioned_throughput } }; update_table_request.GlobalSecondaryIndexUpdates.Add(global_secondary_index_update); } AmazonDynamoDBClient amazon_dynamo_db_client = AWS.GetAmazonDynamoDBClient(); amazon_dynamo_db_client.UpdateTable(update_table_request); modification_results.SuccessfulUpdates.Add(table_name_group.Key); } catch (Exception exception) { modification_results.Errors.Add(new Tuple <string, Exception>(table_name_group.Key, exception)); if (!continue_on_error) { break; } } } } return(modification_results); }
public static async Task <UpdateTableResponse> AddIndexAsync(IAmazonDynamoDB client, string table, string indexname, string partitionkey, string partitionkeytype, string sortkey, string sortkeytype) { if (null == client) { throw new ArgumentNullException("client parameter is null"); } if (string.IsNullOrEmpty(table)) { throw new ArgumentNullException("table parameter is null"); } if (string.IsNullOrEmpty(indexname)) { throw new ArgumentNullException("indexname parameter is null"); } if (string.IsNullOrEmpty(partitionkey)) { throw new ArgumentNullException("partitionkey parameter is null"); } if (string.IsNullOrEmpty(sortkey)) { throw new ArgumentNullException("sortkey parameter is null"); } ProvisionedThroughput pt = new ProvisionedThroughput { ReadCapacityUnits = 10L, WriteCapacityUnits = 5L }; KeySchemaElement kse1 = new KeySchemaElement { AttributeName = partitionkey, KeyType = "HASH" }; KeySchemaElement kse2 = new KeySchemaElement { AttributeName = sortkey, KeyType = "RANGE" }; List <KeySchemaElement> kses = new List <KeySchemaElement> { kse1, kse2 }; Projection p = new Projection { ProjectionType = "ALL" }; var newIndex = new CreateGlobalSecondaryIndexAction() { IndexName = indexname, ProvisionedThroughput = pt, KeySchema = kses, Projection = p }; GlobalSecondaryIndexUpdate update = new GlobalSecondaryIndexUpdate { Create = newIndex }; List <GlobalSecondaryIndexUpdate> updates = new List <GlobalSecondaryIndexUpdate> { update }; AttributeDefinition ad1; if (partitionkeytype == "string") { ad1 = new AttributeDefinition { AttributeName = partitionkey, AttributeType = "S" }; } else { ad1 = new AttributeDefinition { AttributeName = partitionkey, AttributeType = "N" }; } AttributeDefinition ad2; if (sortkeytype == "string") { ad2 = new AttributeDefinition { AttributeName = sortkey, AttributeType = "S" }; } else { ad2 = new AttributeDefinition { AttributeName = sortkey, AttributeType = "N" }; } UpdateTableRequest request = new UpdateTableRequest { TableName = table, AttributeDefinitions = { ad1, ad2 }, GlobalSecondaryIndexUpdates = updates }; var response = await client.UpdateTableAsync(request); return(response); }