0

I'd like to construct a CreateTableRequest object from data annotations in a class. It looks like Amazon provides DynamoDBMapper in the Java SDK, which makes this process simple.

How can I do the same in .NET/C#?

 AmazonDynamoDB dynamoDBClient = new AmazonDynamoDBClient();
 DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient);
 CreateTableRequest req = mapper.generateCreateTableRequest(TestClass.class);
 // Table provision throughput is still required since it cannot be specified in your POJO
 req.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
 // Fire off the CreateTableRequest using the low-level client
 dynamoDBClient.createTable(req);
Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
user246392
  • 2,661
  • 11
  • 54
  • 96

1 Answers1

0

generateCreateTableRequest is unique to the Java SDK with no equivalent (yet) for the .NET SDK.

The general .NET equivalent for Java's DynamoDBMapper is the DynamoDBContext class (docs 1, docs 2). This class provides a high-level .NET object persistence model that enables you to map your client-side classes to Amazon DynamoDB tables.

However, as per docs:

The object persistence model does not provide an API to create, update, or delete tables. It provides only data operations. You can use only the AWS SDK for .NET low-level API to create, update, and delete tables.

You will have to use the low-level .NET API to create tables.

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
  • 1
    Thank you. I feared that'd be the case. It looks like if an attribute is not defined, during insert/update, DynamoDB will auto create it, correct? So, perhaps at minimum I can define the hash and range keys and let app code insert all other attributes. – user246392 Aug 29 '22 at 09:10
  • @user246392 Sorry, not sure what you mean - you mean if you have fields with no `DynamoDBProperty` annotation? How would the app code 'insert' attributes when you're using a class? – Ermiya Eskandary Aug 29 '22 at 09:47
  • That's not what I meant. The annotations will be there. During table creation, I want to skip the heavy lifting when I call the low level .NET APIs after I construct a `CreateTableRequest` object. By attribute, I meant `AttributeDefinition`. – user246392 Aug 29 '22 at 09:51
  • If you have any other questions, please create separate questions to not clutter the comment section – Ermiya Eskandary Aug 29 '22 at 10:35