create_table ( $opt )

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

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • TableName - string - Required - The name of the table you want to create. Allowed characters are a-z, A-Z, 0-9, _ (underscore), - (hyphen) and . (period). [Constraints: The value must be between 3 and 255 characters, and must match the following regular expression pattern: [a-zA-Z0-9_.-]+]
  • KeySchema - array - Required - The KeySchema identifies the primary key as a one attribute primary key (hash) or a composite two attribute (hash-and-range) primary key. Single attribute primary keys have one index value: a HashKeyElement. A composite hash-and-range primary key contains two attribute values: a HashKeyElement and a RangeKeyElement.
    • HashKeyElement - array - Required - A hash key element is treated as the primary key, and can be a string or a number. Single attribute primary keys have one index value. The value can be String, Number, StringSet, NumberSet.
      • AttributeName - string - Required - The AttributeName of the KeySchemaElement.
      • AttributeType - string - Required - The AttributeType of the KeySchemaElement which can be a String or a Number. [Allowed values: S, N, B]
    • RangeKeyElement - array - Optional - A range key element is treated as a secondary key (used in conjunction with the primary key), and can be a string or a number, and is only used for hash-and-range primary keys. The value can be String, Number, StringSet, NumberSet.
      • AttributeName - string - Required - The AttributeName of the KeySchemaElement.
      • AttributeType - string - Required - The AttributeType of the KeySchemaElement which can be a String or a Number. [Allowed values: S, N, B]
  • ProvisionedThroughput - array - Required - Provisioned throughput reserves the required read and write resources for your table in terms of ReadCapacityUnits and WriteCapacityUnits. Values for provisioned throughput depend upon your expected read/write rates, item size, and consistency. Provide the expected number of read and write operations, assuming an item size of 1k and strictly consistent reads. For 2k item size, double the value. For 3k, triple the value, etc. Eventually-consistent reads consume half the resources of strictly consistent reads.
    • ReadCapacityUnits - long - Required - ReadCapacityUnits are in terms of strictly consistent reads, assuming items of 1k. 2k items require twice the ReadCapacityUnits. Eventually-consistent reads only require half the ReadCapacityUnits of stirctly consistent reads.
    • WriteCapacityUnits - long - Required - WriteCapacityUnits are in terms of strictly consistent reads, assuming items of 1k. 2k items require twice the WriteCapacityUnits.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

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

public function create_table($opt = null)
{
    if (!$opt) $opt = array();
    
    return $this->authenticate('CreateTable', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback