本文整理汇总了PHP中Aws\DynamoDb\DynamoDbClient::createTable方法的典型用法代码示例。如果您正苦于以下问题:PHP DynamoDbClient::createTable方法的具体用法?PHP DynamoDbClient::createTable怎么用?PHP DynamoDbClient::createTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\DynamoDb\DynamoDbClient
的用法示例。
在下文中一共展示了DynamoDbClient::createTable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTable
/**
* Create the dynamodb table before tests run.
*/
protected static function createTable()
{
try {
self::$client->describeTable(['TableName' => self::$tableName]);
return;
} catch (DynamoDbException $e) {
// table doesn't exist, create it below
}
self::$client->createTable(['TableName' => self::$tableName, 'AttributeDefinitions' => [['AttributeName' => 'id', 'AttributeType' => 'S']], 'KeySchema' => array(['AttributeName' => 'id', 'KeyType' => 'HASH']), 'ProvisionedThroughput' => ['ReadCapacityUnits' => 5, 'WriteCapacityUnits' => 5]]);
self::$client->waitUntil('TableExists', ['TableName' => self::$tableName]);
}
示例2: createTable
/**
* Create the table
*/
protected static function createTable($wait = false)
{
$tables = self::$dynamodb->listTables();
if (in_array(self::TABLE_NAME, $tables['TableNames'])) {
self::deleteTable(true);
}
self::$dynamodb->createTable(['TableName' => self::TABLE_NAME, 'AttributeDefinitions' => [['AttributeName' => 'key', 'AttributeType' => 'S']], 'KeySchema' => [['AttributeName' => 'key', 'KeyType' => 'HASH']], 'ProvisionedThroughput' => ['ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1]]);
if (!$wait) {
return;
}
self::$dynamodb->waitUntil('TableExists', ['TableName' => self::TABLE_NAME, 'waiter.interval' => 1, 'waiter.max_attempts' => 5]);
}
示例3: createTable
/**
* @param $tableName
* @param DynamoDbIndex $primaryIndex
* @param DynamoDbIndex[] $localSecondaryIndices
* @param DynamoDbIndex[] $globalSecondaryIndices
* @param int $readCapacity
* @param int $writeCapacity
*
* @return bool
* @internal param DynamoDbIndex $primaryKey
*/
public function createTable($tableName, DynamoDbIndex $primaryIndex, array $localSecondaryIndices = [], array $globalSecondaryIndices = [], $readCapacity = 5, $writeCapacity = 5)
{
$attrDef = $primaryIndex->getAttributeDefinitions();
foreach ($globalSecondaryIndices as $gsi) {
$gsiDef = $gsi->getAttributeDefinitions();
$attrDef = array_merge($attrDef, $gsiDef);
}
foreach ($localSecondaryIndices as $lsi) {
$lsiDef = $lsi->getAttributeDefinitions();
$attrDef = array_merge($attrDef, $lsiDef);
}
$attrDef = array_values($attrDef);
$keySchema = $primaryIndex->getKeySchema();
$gsiDef = [];
foreach ($globalSecondaryIndices as $globalSecondaryIndex) {
$gsiDef[] = ["IndexName" => $globalSecondaryIndex->getName(), "KeySchema" => $globalSecondaryIndex->getKeySchema(), "Projection" => $globalSecondaryIndex->getProjection(), "ProvisionedThroughput" => ["ReadCapacityUnits" => $readCapacity, "WriteCapacityUnits" => $writeCapacity]];
}
$lsiDef = [];
foreach ($localSecondaryIndices as $localSecondaryIndex) {
$lsiDef[] = ["IndexName" => $localSecondaryIndex->getName(), "KeySchema" => $localSecondaryIndex->getKeySchema(), "Projection" => $localSecondaryIndex->getProjection()];
}
$args = ["TableName" => $tableName, "ProvisionedThroughput" => ["ReadCapacityUnits" => $readCapacity, "WriteCapacityUnits" => $writeCapacity], "AttributeDefinitions" => $attrDef, "KeySchema" => $keySchema];
if ($gsiDef) {
$args["GlobalSecondaryIndexes"] = $gsiDef;
}
if ($lsiDef) {
$args["LocalSecondaryIndexes"] = $lsiDef;
}
$result = $this->db->createTable($args);
if (isset($result['TableDescription']) && $result['TableDescription']) {
return true;
} else {
return false;
}
}
示例4: createTable
/**
* @param string $tableName
*/
protected function createTable($tableName)
{
try {
$this->client->describeTable(['TableName' => $tableName]);
} catch (ResourceNotFoundException $e) {
$this->client->createTable(['AttributeDefinitions' => [['AttributeName' => 'id', 'AttributeType' => 'S']], 'TableName' => $tableName, 'KeySchema' => [['AttributeName' => 'id', 'KeyType' => 'HASH']], 'ProvisionedThroughput' => ['ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1]]);
}
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client');
$this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name');
try {
$this->dynamoDbClient->describeTable(['TableName' => $this->tableName]);
echo 'Table ' . $this->tableName . ' already exists.' . "\n";
} catch (DynamoDbException $e) {
if (strpos($e->getMessage(), 'ResourceNotFoundException') !== false) {
echo 'Creating ' . $this->tableName . ' table ...';
$this->dynamoDbClient->createTable($this->getTableConfiguration());
$this->dynamoDbClient->waitUntil('TableExists', ['TableName' => $this->tableName, '@waiter' => ['delay' => 3, 'maxAttempts' => 20]]);
echo ' done!' . "\n";
} else {
throw $e;
}
}
}
示例6: createTable
/**
* Executes the CreateTable operation.
*
* @param string $tableName The name of the table to create.
* @param array $attributeDefinitions An array of attributes that describe the key schema for the table and indexes.
* @param array $keySchema Specifies the attributes that make up the primary key for a table or an index
* @param array $provisionedThroughput Represents the provisioned throughput settings for a specified table or index.
* @param array $localSecondaryIndexes One or more local secondary indexes (the maximum is five) to be created on the table.
* @param array $globalSecondaryIndexes One or more global secondary indexes (the maximum is five) to be created on the table.
*
* @return Guzzle\Service\Resource\Model
*
* @see http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_createTable
*/
public function createTable($tableName, array $attributeDefinitions, array $keySchema, array $provisionedThroughput, array $localSecondaryIndexes = null, array $globalSecondaryIndexes = null)
{
$args = ['AttributeDefinitions' => $attributeDefinitions, 'TableName' => $tableName, 'KeySchema' => $keySchema, 'ProvisionedThroughput' => $provisionedThroughput];
if ($localSecondaryIndexes !== null) {
$args['LocalSecondaryIndexes'] = $localSecondaryIndexes;
}
if ($globalSecondaryIndexes !== null) {
$args['GlobalSecondaryIndexes'] = $globalSecondaryIndexes;
}
return $this->client->createTable($args);
}
示例7: createTable
/**
* Create table via the create_table call
* @param string $table The name of the table
* @param Table\KeySchema $keySchama
* @param Table\ProvisionedThroughput $provisionedThroughput
* @return Table\TableDescription
*/
public function createTable($table, Table\KeySchema $keySchama, Table\ProvisionedThroughput $provisionedThroughput)
{
if (null !== $this->logger) {
$this->log('Create table ' . $table);
}
$parameters = array('TableName' => $table, 'KeySchema' => $keySchama->getForDynamoDB(), 'ProvisionedThroughput' => $provisionedThroughput->getForDynamoDB());
if (null !== $this->logger) {
$this->log('TableCreate request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
}
$response = $this->connector->createTable($parameters);
if (null !== $this->logger) {
$this->log('TableCreate request response : ' . print_r($response, true), Logger::DEBUG);
}
}
示例8: testCreatesTable
/**
* Ensures that a DynamoDB table can be created
*/
public function testCreatesTable()
{
self::log("Waiting until {$this->table} does not exist");
$this->client->waitUntil('TableNotExists', $this->table);
self::log("Attempting to create {$this->table}");
$this->client->createTable(array('TableName' => $this->table, 'KeySchema' => array('HashKeyElement' => array('AttributeName' => 'foo', 'AttributeType' => 'S'), 'RangeKeyElement' => array('AttributeName' => 'bar', 'AttributeType' => 'N')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 10)));
// Check/wait until the table exists
self::log("Table created. Waiting until it exists.");
$this->client->waitUntil('TableExists', $this->table);
self::log("Table exists");
// Ensure that the fields were set properly
$result = $this->client->describeTable(array('TableName' => $this->table));
self::log("Ensuring the table was created with the proper values");
$this->assertEquals($this->table, $result['Table']['TableName']);
$this->assertEquals('foo', $result['Table']['KeySchema']['HashKeyElement']['AttributeName']);
$this->assertEquals('S', $result['Table']['KeySchema']['HashKeyElement']['AttributeType']);
$this->assertEquals('bar', $result['Table']['KeySchema']['RangeKeyElement']['AttributeName']);
$this->assertEquals('N', $result['Table']['KeySchema']['RangeKeyElement']['AttributeType']);
$this->assertEquals(10, $result['Table']['ProvisionedThroughput']['ReadCapacityUnits']);
$this->assertEquals(10, $result['Table']['ProvisionedThroughput']['WriteCapacityUnits']);
}
示例9: createDynamoDb
private function createDynamoDb(\Aws\DynamoDb\DynamoDbClient $client, $prefix = null)
{
$tablesList = explode(' ', 'oauth_access_tokens oauth_authorization_codes oauth_clients oauth_jwt oauth_public_keys oauth_refresh_tokens oauth_scopes oauth_users');
$nbTables = count($tablesList);
$client->createTable(array('TableName' => $prefix . 'oauth_access_tokens', 'AttributeDefinitions' => array(array('AttributeName' => 'access_token', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'access_token', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_authorization_codes', 'AttributeDefinitions' => array(array('AttributeName' => 'authorization_code', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'authorization_code', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_clients', 'AttributeDefinitions' => array(array('AttributeName' => 'client_id', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'client_id', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_jwt', 'AttributeDefinitions' => array(array('AttributeName' => 'client_id', 'AttributeType' => 'S'), array('AttributeName' => 'subject', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'client_id', 'KeyType' => 'HASH'), array('AttributeName' => 'subject', 'KeyType' => 'RANGE')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_public_keys', 'AttributeDefinitions' => array(array('AttributeName' => 'client_id', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'client_id', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_refresh_tokens', 'AttributeDefinitions' => array(array('AttributeName' => 'refresh_token', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'refresh_token', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_scopes', 'AttributeDefinitions' => array(array('AttributeName' => 'scope', 'AttributeType' => 'S'), array('AttributeName' => 'is_default', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'scope', 'KeyType' => 'HASH')), 'GlobalSecondaryIndexes' => array(array('IndexName' => 'is_default-index', 'KeySchema' => array(array('AttributeName' => 'is_default', 'KeyType' => 'HASH')), 'Projection' => array('ProjectionType' => 'ALL'), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1))), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
$client->createTable(array('TableName' => $prefix . 'oauth_users', 'AttributeDefinitions' => array(array('AttributeName' => 'username', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'username', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
// Wait for creation
$nbTableCreated = 0;
while ($nbTableCreated != $nbTables) {
$nbTableCreated = 0;
foreach ($tablesList as $key => $table) {
try {
$result = $client->describeTable(array('TableName' => $prefix . $table));
if ($result['Table']['TableStatus'] == 'ACTIVE') {
$nbTableCreated++;
}
} catch (\Aws\DynamoDb\Exception\DynamoDbException $e) {
// Table does not exist : nothing to do
$nbTableCreated++;
}
}
if ($nbTableCreated != $nbTables) {
sleep(1);
}
}
}