Adds a new table to your account.
The table name must be unique among those associated with the AWS Account issuing the request, and the AWS Region that receives the request (e.g. us-east-1 ).
The CreateTable operation triggers an asynchronous workflow to begin creating the table. Amazon DynamoDB immediately returns the state of the table ( CREATING ) until the table is in the ACTIVE state. Once the table is in the ACTIVE state, you can perform data plane operations.
Declaration Syntax
C# |
public CreateTableResponse CreateTable( CreateTableRequest createTableRequest )
Parameters
- createTableRequest (CreateTableRequest)
- Container for the necessary parameters to execute the CreateTable service method on AmazonDynamoDB.
Return Value
The response from the CreateTable service method, as returned by AmazonDynamoDB.
Examples
This example shows how to create a new table with a single hash-key component.
CopyCreateTable sample
// Create a client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Define table schema: // Table has string hash- and range-keys. KeySchema schema = new KeySchema { HashKeyElement = new KeySchemaElement { AttributeName = "Author", AttributeType = "S" }, RangeKeyElement = new KeySchemaElement { AttributeName = "Title", AttributeType = "S" } }; // Define table throughput: // Table has capacity of 20 reads and 50 writes ProvisionedThroughput throughput = new ProvisionedThroughput { ReadCapacityUnits = 20, WriteCapacityUnits = 50 }; // Configure the CreateTable request CreateTableRequest request = new CreateTableRequest { TableName = "SampleTable", KeySchema = schema, ProvisionedThroughput = throughput }; // View new table properties TableDescription tableDescription = client.CreateTable(request).CreateTableResult.TableDescription; Console.WriteLine("Table name: {0}", tableDescription.TableName); Console.WriteLine("Creation time: {0}", tableDescription.CreationDateTime); Console.WriteLine("Item count: {0}", tableDescription.ItemCount); Console.WriteLine("Table size (bytes): {0}", tableDescription.TableSizeBytes); Console.WriteLine("Table status: {0}", tableDescription.TableStatus); KeySchema tableSchema = tableDescription.KeySchema; Console.WriteLine("Hash-key: Name = {0}, Type = {1}", tableSchema.HashKeyElement.AttributeName, tableSchema.HashKeyElement.AttributeType); Console.WriteLine("Range-key: Name = {0}, Type = {1}", tableSchema.RangeKeyElement.AttributeName, tableSchema.RangeKeyElement.AttributeType); Console.WriteLine("Throughput: Reads = {0}, Writes = {1}", tableDescription.ProvisionedThroughput.ReadCapacityUnits, tableDescription.ProvisionedThroughput.WriteCapacityUnits);
Exceptions
Exception | Condition |
---|---|
ResourceInUseException | |
LimitExceededException | |
InternalServerErrorException |