Skip to content

Instantly share code, notes, and snippets.

@oguzhancagliyan
Created September 30, 2020 00:11
Show Gist options
  • Save oguzhancagliyan/b64de7eccdc10174552ff3bcafbea9c1 to your computer and use it in GitHub Desktop.
Save oguzhancagliyan/b64de7eccdc10174552ff3bcafbea9c1 to your computer and use it in GitHub Desktop.
public class DynamoDbMovieSeeder : IDynamoDbSeeder
{
public void Seed(AmazonDynamoDBClient client)
{
MovieEntity model = new MovieEntity
{
MovieId = TestConstants.GetMovieId(),
DirectorId = TestConstants.GetDirectorId(),
MovieName = TestConstants.GetMovieName(),
CreateDate = DateTime.UtcNow.ToComparableDateString()
};
DynamoDbSeeder.Add(client, model);
}
public void CreateTable(AmazonDynamoDBClient client)
{
var postTableCreateRequest = new CreateTableRequest
{
AttributeDefinitions = new List<AttributeDefinition>
{
new AttributeDefinition
{
AttributeName = nameof(MovieEntity.DirectorId),
AttributeType = ScalarAttributeType.S
},
new AttributeDefinition
{
AttributeName = nameof(MovieEntity.CreateDate),
AttributeType = ScalarAttributeType.S
},
new AttributeDefinition()
{
AttributeName = nameof(MovieEntity.MovieId),
AttributeType = ScalarAttributeType.S
}
},
TableName = "Movies",
KeySchema = new List<KeySchemaElement>()
{
new KeySchemaElement()
{
AttributeName = nameof(MovieEntity.DirectorId),
KeyType = KeyType.HASH
},
new KeySchemaElement()
{
AttributeName = nameof(MovieEntity.CreateDate),
KeyType = KeyType.RANGE
}
},
GlobalSecondaryIndexes = new List<GlobalSecondaryIndex>
{
new GlobalSecondaryIndex
{
Projection = new Projection
{
ProjectionType = ProjectionType.ALL
},
IndexName = Constants.MoiveTableMovieIdGsi,
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement
{
AttributeName = nameof(MovieEntity.MovieId),
KeyType = KeyType.HASH
}
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 5
}
}
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 6
},
};
CreateTableResponse result = client.CreateTableAsync(postTableCreateRequest).GetAwaiter().GetResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment