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.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
---|---|---|---|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
---|---|
A |
Examples
Create a new table with a Hash Key.
// Instantiate the class $dynamodb = new AmazonDynamoDB(); $table_name = 'my-table' . time(); #################################################################### # Create a new DynamoDB table $response = $dynamodb->create_table(array( 'TableName' => $table_name, 'KeySchema' => array( 'HashKeyElement' => array( 'AttributeName' => 'ID', 'AttributeType' => AmazonDynamoDB::TYPE_NUMBER ), 'RangeKeyElement' => array( 'AttributeName' => 'Date', 'AttributeType' => AmazonDynamoDB::TYPE_NUMBER ) ), 'ProvisionedThroughput' => array( 'ReadCapacityUnits' => 50, 'WriteCapacityUnits' => 50 ) )); // Check for success... if ($response->isOK()) { echo '# Kicked off the creation of the DynamoDB table...' . PHP_EOL; } else { print_r($response); } #################################################################### # Sleep and poll until the table has been created $count = 0; do { sleep(1); $count++; $response = $dynamodb->describe_table(array( 'TableName' => $table_name )); } while ((string) $response->body->Table->TableStatus !== 'ACTIVE'); echo "The table \"${table_name}\" has been created (slept ${count} seconds)." . PHP_EOL; #################################################################### # Collect all table names in the account echo PHP_EOL . PHP_EOL; echo '# Collecting a complete list of tables in the account...' . PHP_EOL; $response = $dynamodb->list_tables(); print_r($response->body->TableNames->to_array()->getArrayCopy()); #################################################################### # Describe a specific table echo PHP_EOL . PHP_EOL; echo "# Describing the \"${table_name}\" table..." . PHP_EOL; $response = $dynamodb->describe_table(array( 'TableName' => $table_name )); print_r($response->body); #################################################################### # Updating the table echo PHP_EOL . PHP_EOL; echo "# Updating the \"${table_name}\" table..." . PHP_EOL; $dynamodb->update_table(array( 'TableName' => $table_name, 'ProvisionedThroughput' => array( 'ReadCapacityUnits' => 400, 'WriteCapacityUnits' => 400 ) )); $table_status = $dynamodb->describe_table(array( 'TableName' => $table_name )); // Check for success... if ($table_status->isOK()) { print_r($table_status->body->Table->ProvisionedThroughput->to_array()->getArrayCopy()); } else { print_r($table_status); } #################################################################### # Sleep and poll until the table has been updated. $count = 0; do { sleep(5); $count += 5; $response = $dynamodb->describe_table(array( 'TableName' => $table_name )); } while ((string) $response->body->Table->TableStatus !== 'ACTIVE'); echo "The table \"${table_name}\" has been updated (slept ${count} seconds)." . PHP_EOL; #################################################################### # Deleting the table echo PHP_EOL . PHP_EOL; echo "# Deleting the \"${table_name}\" table..." . PHP_EOL; $response = $dynamodb->delete_table(array( 'TableName' => $table_name )); // Check for success... if ($response->isOK()) { echo 'The table is in the process of deleting...' . PHP_EOL; } else { print_r($response); } #################################################################### # Sleep and poll until the table has been deleted. $count = 0; do { sleep(1); $count++; $response = $dynamodb->describe_table(array( 'TableName' => $table_name )); } while ((integer) $response->status !== 400); echo "The table \"${table_name}\" has been deleted (slept ${count} seconds)." . PHP_EOL;
Source
Method defined in services/dynamodb.class.php | Toggle source view (6 lines) | View on GitHub