4

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.

MaYaN
  • 6,683
  • 12
  • 57
  • 109

2 Answers2

2

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
};
therightstuff
  • 833
  • 1
  • 16
  • 21
1

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
});
MaYaN
  • 6,683
  • 12
  • 57
  • 109