forked from ACloudGuru/dynamodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createtables.php
160 lines (146 loc) · 4.82 KB
/
createtables.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
//Code is provided by AWS and available here; http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AppendixSampleDataCodePHP.html
// Date now needs to be set, which I guess is a good thing!
date_default_timezone_set('Europe/London');
// Find out what the issues are:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
require '/var/www/html/vendor/autoload.php';
use Aws\DynamoDb\DynamoDbClient;
$client = DynamoDbClient::factory(array(
'region' => 'eu-west-1', // replace with your desired region visit http://docs.aws.amazon.com/general/latest/gr/rande.html to get your regions.
'version' => '2012-08-10' // Now needs a version
));
$tableNames = array();
$tableName = 'ProductCatalog';
echo "Creating table $tableName..." . PHP_EOL;
$response = $client->createTable(array(
'TableName' => $tableName,
'AttributeDefinitions' => array(
array(
'AttributeName' => 'Id',
'AttributeType' => 'N'
)
),
'KeySchema' => array(
array(
'AttributeName' => 'Id',
'KeyType' => 'HASH'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 5
)
));
$tableNames[] = $tableName;
$tableName = 'Forum';
echo "Creating table $tableName..." . PHP_EOL;
$response = $client->createTable(array(
'TableName' => $tableName,
'AttributeDefinitions' => array(
array(
'AttributeName' => 'Name',
'AttributeType' => 'S'
)
),
'KeySchema' => array(
array(
'AttributeName' => 'Name',
'KeyType' => 'HASH'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 5
)
));
$tableNames[] = $tableName;
$tableName = 'Thread';
echo "Creating table $tableName..." . PHP_EOL;
$response = $client->createTable(array(
'TableName' => $tableName,
'AttributeDefinitions' => array(
array(
'AttributeName' => 'ForumName',
'AttributeType' => 'S'
),
array(
'AttributeName' => 'Subject',
'AttributeType' => 'S'
)
),
'KeySchema' => array(
array(
'AttributeName' => 'ForumName',
'KeyType' => 'HASH'
),
array(
'AttributeName' => 'Subject',
'KeyType' => 'RANGE'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 5
)
));
$tableNames[] = $tableName;
$tableName = 'Reply';
echo "Creating table $tableName..." . PHP_EOL;
$response = $client->createTable(array(
'TableName' => $tableName,
'AttributeDefinitions' => array(
array(
'AttributeName' => 'Id',
'AttributeType' => 'S'
),
array(
'AttributeName' => 'ReplyDateTime',
'AttributeType' => 'S'
),
array(
'AttributeName' => 'PostedBy',
'AttributeType' => 'S'
)
),
'LocalSecondaryIndexes' => array(
array(
'IndexName' => 'PostedBy-index',
'KeySchema' => array(
array(
'AttributeName' => 'Id',
'KeyType' => 'HASH'
),
array(
'AttributeName' => 'PostedBy',
'KeyType' => 'RANGE'
),
),
'Projection' => array(
'ProjectionType' => 'KEYS_ONLY',
),
),
),
'KeySchema' => array(
array(
'AttributeName' => 'Id',
'KeyType' => 'HASH'
),
array(
'AttributeName' => 'ReplyDateTime',
'KeyType' => 'RANGE'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 5
)
));
$tableNames[] = $tableName;
foreach($tableNames as $tableName) {
echo "Waiting for table $tableName to be created." . PHP_EOL;
$client->waitUntil('TableExists', array('TableName' => $tableName)); // Changed from v2
echo "Table $tableName has been created." . PHP_EOL;
}