/// <summary> /// Builds a CreateTableRequest object from an entity type marked up with the object model; other parameters /// set table properties from that. Only supports string, number and byte array properties, others should /// be unmarked. Generally, don't create a DBProperty unless you need to use in a Filter, and rely on /// DynamoDb client library to figure out how to store. /// We will default both throughput on tables and GSI to on demand if you don't provide them /// We will default projections to all, if you don't provide them /// </summary> /// <param name="provisonedThroughput">What is the provisioned throughput for the table. Defaults to 10 read and write units</param> /// <param name="gsiProjections">How are global secondary indexes projected; defaults to all</param> /// <param name="billingMode">What billing mode (provisioned or request)</param> /// <param name="sseSpecification"></param> /// <param name="streamSpecification"></param> /// <param name="tags"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public CreateTableRequest GenerateCreateTableMapper <T>( DynamoDbCreateProvisionedThroughput provisonedThroughput, DynamoGSIProjections gsiProjections = null, BillingMode billingMode = null, SSESpecification sseSpecification = null, StreamSpecification streamSpecification = null, IEnumerable <Tag> tags = null) { var docType = typeof(T); string tableName = GetTableName <T>(docType); var createTableRequest = new CreateTableRequest(tableName, GetPrimaryKey <T>(docType).ToList()); AddTableProvisionedThrougput <T>(provisonedThroughput, createTableRequest); createTableRequest.AttributeDefinitions.AddRange(GetAttributeDefinitions <T>(docType)); createTableRequest.GlobalSecondaryIndexes.AddRange(GetGlobalSecondaryIndices <T>(docType).Select(entry => entry.Value)); AddGSIProvisionedThroughput <T>(provisonedThroughput, createTableRequest); AddGSIProjections(gsiProjections, createTableRequest); createTableRequest.LocalSecondaryIndexes.AddRange(GetLocalSecondaryIndices <T>(docType)); createTableRequest.BillingMode = billingMode ?? BillingMode.PROVISIONED; createTableRequest.SSESpecification = sseSpecification ?? new SSESpecification { Enabled = true }; createTableRequest.StreamSpecification = streamSpecification ?? new StreamSpecification { StreamEnabled = true, StreamViewType = StreamViewType.NEW_IMAGE }; createTableRequest.Tags = tags != null?tags.ToList() : new List <Tag> { new Tag { Key = "outbox", Value = "brighter_outbox" } }; return(createTableRequest); }
private void AddGSIProvisionedThroughput <T>(DynamoDbCreateProvisionedThroughput provisonedThroughput, CreateTableRequest createTableRequest) { if (provisonedThroughput != null) { foreach (var globalSecondaryIndex in createTableRequest.GlobalSecondaryIndexes) { if (provisonedThroughput.GSIThroughputs.TryGetValue(globalSecondaryIndex.IndexName, out ProvisionedThroughput gsiProvisonedThroughput)) { globalSecondaryIndex.ProvisionedThroughput = gsiProvisonedThroughput; } else { globalSecondaryIndex.ProvisionedThroughput = new ProvisionedThroughput(OnDemand, OnDemand); } } } else { foreach (var globalSecondaryIndex in createTableRequest.GlobalSecondaryIndexes) { globalSecondaryIndex.ProvisionedThroughput = new ProvisionedThroughput(OnDemand, OnDemand); } } }
public void When_Creating_A_Table_With_Provisioned_Throughput() { //arrange var tableRequestFactory = new DynamoDbTableFactory(); var provisonedThroughput = new DynamoDbCreateProvisionedThroughput ( table: new ProvisionedThroughput() { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, gsiThroughputs: new Dictionary <string, ProvisionedThroughput>() { { "GlobalSecondaryIndex", new ProvisionedThroughput(readCapacityUnits: 11, writeCapacityUnits: 11) } } ); //act CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(provisonedThroughput); //assert Assert.Equal(10, tableRequest.ProvisionedThroughput.ReadCapacityUnits); Assert.Equal(10, tableRequest.ProvisionedThroughput.WriteCapacityUnits); Assert.Equal(11, tableRequest.GlobalSecondaryIndexes.First(gsi => gsi.IndexName == "GlobalSecondaryIndex").ProvisionedThroughput.ReadCapacityUnits); Assert.Equal(11, tableRequest.GlobalSecondaryIndexes.First(gsi => gsi.IndexName == "GlobalSecondaryIndex").ProvisionedThroughput.WriteCapacityUnits); }
private void AddTableProvisionedThrougput <T>(DynamoDbCreateProvisionedThroughput provisonedThroughput, CreateTableRequest createTableRequest) { if (provisonedThroughput != null) { createTableRequest.ProvisionedThroughput = provisonedThroughput.Table; } else { createTableRequest.ProvisionedThroughput = new ProvisionedThroughput(OnDemand, OnDemand); } }