MaYaN
MaYaN

Reputation: 6996

How can I create an On-Demand DynamoDB table in C#?

I cannot seem to find an example of creating an On-Demand DynamoDB table in C#.

The C# examples on AWS only describes how to create a table with provisioned throughput.

Upvotes: 4

Views: 874

Answers (2)

therightstuff
therightstuff

Reputation: 1017

I'm surprised by @MaYaN's answer, I've got it working nicely with

CreateTableRequest createRequest = new CreateTableRequest 
{
    TableName = "Foo",
    AttributeDefinitions = new List<AttributeDefinition> {
        new AttributeDefinition {
            AttributeName = "Id",
            AttributeType = ScalarAttributeType.S,
        }
    }, 
    KeySchema = new List<KeySchemaElement> {
        new KeySchemaElement("Id", KeyType.HASH)
    }, 
    BillingMode = BillingMode.PAY_PER_REQUEST
};

Upvotes: 3

MaYaN
MaYaN

Reputation: 6996

In my opinion the way this is supported in the SDK is unintuitive.

One would need to first create a table with a default ProvisionedThroughput then update the table and set the billing to: PAY_PER_REQUEST

CreateTableRequest createRequest = new CreateTableRequest 
{
    TableName = "Foo",
    AttributeDefinitions = new List<AttributeDefinition> {
        new AttributeDefinition {
            AttributeName = "Id",
            AttributeType = ScalarAttributeType.S,
        }
    }, 
    KeySchema = new List<KeySchemaElement> {
        new KeySchemaElement("Id", KeyType.HASH)
    }, 
    ProvisionedThroughput = new ProvisionedThroughput(1, 1)
};

await client.CreateTableAsync(createRequest);
// Wait for it to be created

await client.UpdateTableAsync(new UpdateTableRequest
{
    TableName = name,
    BillingMode = BillingMode.PAY_PER_REQUEST
});

Upvotes: 1

Related Questions