jbuiss0n
jbuiss0n

Reputation: 467

DynamoDB model/schema creation?

I've an application write in C#/.NET, it's a very simple Forum like website. Currently, I'm using SqlServer with EntityFramework CodeMigration as my Data Access Layer.

I'm considering to migrate all my data to DynamoDB, I've already try some tutorial and read some docs, but I'm currently stuck with the model creation...

Using EntityFramework CodeMigration, I just create some C# Entities, and then use the EF migration scaffolder to write the C# code to setup my DB (this script contains all my tables/indexes/Keys/... creations). I find this very useful, all my dabatase schema is scripted, easy to update and version with the rest of my project.

So now my question, is there a way to do the same thing using DynamoDB .NET SDK ?

I've already read the following docs about tables creation, but I've almost 50 tables, and it's a real pain to write all the setup by hand, and as I've already defined my Entities, their must be something to automatically create table base and my Entities ?

Here is a sample Entity I'm using, and the table creation script corresponding:

[DynamoDBTable("ProductCatalog")]
public class Book
{
    [DynamoDBHashKey]
    public int Id { get; set; }
    [DynamoDBProperty]
    public string Title { get; set; }
    [DynamoDBProperty]
    public string ISBN { get; set; }
    [DynamoDBProperty("Authors")]
    public List<string> BookAuthors { get; set; }
}

var request = new CreateTableRequest
{
    TableName = "ProductCatalog",
    AttributeDefinitions = new List<AttributeDefinition>
    {
        new AttributeDefinition
        {
        AttributeName = "Id",
        AttributeType = "N"
        },
        new AttributeDefinition
        {
        AttributeName = "ISBN",
        AttributeType = "S"
        }
    },
    KeySchema = new List<KeySchemaElement>
    {
        new KeySchemaElement
        {
        AttributeName = "Id",
        KeyType = "HASH"
        },
        new KeySchemaElement
        {
        AttributeName = "ISBN",
        KeyType = "RANGE"
        }
    },
    ProvisionedThroughput = new ProvisionedThroughput
    {
        ReadCapacityUnits = 1,
        WriteCapacityUnits = 1
    },

};
var response = client.CreateTable(request);

Any advice ? To I miss something?

Upvotes: 2

Views: 1365

Answers (1)

Pavel Safronov
Pavel Safronov

Reputation: 1286

Unfortunately, this is not currently possible to do with the AWS SDK for .NET. If you wish, you can open an issue for a feature request for this in the official GitHub repo. The SDK is also open-sourced, so if you do implement something that you feel can be beneficial to other developers, you can submit a pull request to include your source in the SDK.

Upvotes: 1

Related Questions