· 9 years ago · Jan 27, 2017, 08:48 AM
1<?php
2require 'vendor/autoload.php';
3
4use Aws\DynamoDb\DynamoDbClient;
5
6$client = DynamoDbClient::factory(array(
7 'key' => '',
8 'secret' => '',
9 'region' => ''
10));
11
12$response = $client->listTables();
13
14//Check if table exists or not
15if (!in_array('usersTable',$response['TableNames'])) {
16 //Create an "errors" table
17 $client->createTable(array(
18 'TableName' => 'usersTable',
19 'AttributeDefinitions' => array(
20 array(
21 'AttributeName' => 'userID',
22 'AttributeType' => 'N'
23 ),
24 array(
25 'AttributeName' => 'name',
26 'AttributeType' => 'S'
27 )
28 ),
29 'KeySchema' => array(
30 array(
31 'AttributeName' => 'userID',
32 'KeyType' => 'HASH'
33 ),
34 array(
35 'AttributeName' => 'name',
36 'KeyType' => 'RANGE'
37 )
38 ),
39 'ProvisionedThroughput' => array(
40 'ReadCapacityUnits' => 15,
41 'WriteCapacityUnits' => 25
42 )
43 ));
44 // Wait until the table is created and active
45 $client->waitUntil('TableExists', array(
46 'TableName' => 'usersTable'
47 ));
48}
49?>