· 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' => 'AKIAJ6LQADPNP5Y4TBQA',
8 'secret' => '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',
9 'region' => 'ap-southeast-2'
10));
11
12$response = $client->listTables();
13
14//Check if table exists or not
15if (!in_array('chatTable',$response['TableNames'])) {
16 //Create an "errors" table
17 $client->createTable(array(
18 'TableName' => 'chatTable',
19 'AttributeDefinitions' => array(
20 array(
21 'AttributeName' => 'chatID',
22 'AttributeType' => 'N'
23 ),
24 array(
25 'AttributeName' => 'time',
26 'AttributeType' => 'N'
27 )
28 ),
29 'KeySchema' => array(
30 array(
31 'AttributeName' => 'chatID',
32 'KeyType' => 'HASH'
33 ),
34 array(
35 'AttributeName' => 'time',
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' => 'chatTable'
47 ));
48 echo "Table is created";
49
50}
51?>