forked from ACloudGuru/dynamodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploaddata.php
245 lines (226 loc) · 11.2 KB
/
uploaddata.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
// 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
'version' => '2012-08-10' // Now needs a version
));
# Setup some local variables for dates
date_default_timezone_set('UTC');
$oneDayAgo = date('Y-m-d H:i:s', strtotime('-1 days'));
$sevenDaysAgo = date('Y-m-d H:i:s', strtotime('-7 days'));
$fourteenDaysAgo = date('Y-m-d H:i:s', strtotime('-14 days'));
$twentyOneDaysAgo = date('Y-m-d H:i:s', strtotime('-21 days'));
$tableName = 'ProductCatalog';
echo "Adding data to the $tableName table..." . PHP_EOL;
$response = $client->batchWriteItem(array(
'RequestItems' => array(
$tableName => array(
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '1101'),
'Title' => array('S' => 'Book 101 Title'),
'ISBN' => array('S' => '111-1111111111'),
'Authors' => array('SS' => array('Author1')),
'Price' => array('N' => '2'),
'Dimensions' => array('S' => '8.5 x 11.0 x 0.5'),
'PageCount' => array('N' => '500'),
'InPublication' => array('N' => '1'),
'ProductCategory' => array('S' => 'Book')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '102'),
'Title' => array('S' => 'Book 102 Title'),
'ISBN' => array('S' => '222-2222222222'),
'Authors' => array('SS' => array('Author1', 'Author2')),
'Price' => array('N' => '20'),
'Dimensions' => array('S' => '8.5 x 11.0 x 0.8'),
'PageCount' => array('N' => '600'),
'InPublication' => array('N' => '1'),
'ProductCategory' => array('S' => 'Book')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '103'),
'Title' => array('S' => 'Book 103 Title'),
'ISBN' => array('S' => '333-3333333333'),
'Authors' => array('SS' => array('Author1', 'Author2')),
'Price' => array('N' => '2000'),
'Dimensions' => array('S' => '8.5 x 11.0 x 1.5'),
'PageCount' => array('N' => '600'),
'InPublication' => array('N' => '0'),
'ProductCategory' => array('S' => 'Book')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '201'),
'Title' => array('S' => '18-Bike-201'),
'Description' => array('S' => '201 Description'),
'BicycleType' => array('S' => 'Road'),
'Brand' => array('S' => 'Mountain A'),
'Price' => array('N' => '100'),
'Gender' => array('S' => 'M'),
'Color' => array('SS' => array('Red', 'Black')),
'ProductCategory' => array('S' => 'Bicycle')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '202'),
'Title' => array('S' => '21-Bike-202'),
'Description' => array('S' => '202 Description'),
'BicycleType' => array('S' => 'Road'),
'Brand' => array('S' => 'Brand-Company A'),
'Price' => array('N' => '200'),
'Gender' => array('S' => 'M'),
'Color' => array('SS' => array('Green', 'Black')),
'ProductCategory' => array('S' => 'Bicycle')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '203'),
'Title' => array('S' => '19-Bike-203'),
'Description' => array('S' => '203 Description'),
'BicycleType' => array('S' => 'Road'),
'Brand' => array('S' => 'Brand-Company B'),
'Price' => array('N' => '300'),
'Gender' => array('S' => 'W'),
'Color' => array('SS' => array('Red', 'Green', 'Black')),
'ProductCategory' => array('S' => 'Bicycle')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '204'),
'Title' => array('S' => '18-Bike-204'),
'Description' => array('S' => '204 Description'),
'BicycleType' => array('S' => 'Mountain'),
'Brand' => array('S' => 'Brand-Company B'),
'Price' => array('N' => '400'),
'Gender' => array('S' => 'W'),
'Color' => array('SS' => array('Red')),
'ProductCategory' => array('S' => 'Bicycle')
)
),
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('N' => '205'),
'Title' => array('S' => '20-Bike-205'),
'Description' => array('S' => '205 Description'),
'BicycleType' => array('S' => 'Hybrid'),
'Brand' => array('S' => 'Brand-Company C'),
'Price' => array('N' => '500'),
'Gender' => array('S' => 'B'),
'Color' => array('SS' => array('Red', 'Black')),
'ProductCategory' => array('S' => 'Bicycle')
)
)
)
),
),
));
echo "done." . PHP_EOL;
$tableName = 'Forum';
echo "Adding data to the $tableName table..." . PHP_EOL;
$response = $client->batchWriteItem(array(
'RequestItems' => array(
$tableName => array(
array(
'PutRequest' => array(
'Item' => array(
'Name' => array('S' => 'Amazon DynamoDB'),
'Category' => array('S' => 'Amazon Web Services'),
'Threads' => array('N' => '0'),
'Messages' => array('N' => '0'),
'Views' => array('N' => '1000')
)
)
),
array(
'PutRequest' => array(
'Item' => array(
'Name' => array('S' => 'Amazon S3'),
'Category' => array('S' => 'Amazon Web Services'),
'Threads' => array('N' => '0')
)
)
),
)
)
));
echo "done." . PHP_EOL;
$tableName = 'Reply';
echo "Adding data to the $tableName table..." . PHP_EOL;
$response = $client->batchWriteItem(array(
'RequestItems' => array(
$tableName => array(
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('S' => 'Amazon DynamoDB#DynamoDB Thread 1'),
'ReplyDateTime' => array('S' => $fourteenDaysAgo),
'Message' => array('S' => 'DynamoDB Thread 1 Reply 2 text'),
'PostedBy' => array('S' => 'User B')
)
)
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('S' => 'Amazon DynamoDB#DynamoDB Thread 2'),
'ReplyDateTime' => array('S' => $twentyOneDaysAgo),
'Message' => array('S' => 'DynamoDB Thread 2 Reply 3 text'),
'PostedBy' => array('S' => 'User B')
)
)
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('S' => 'Amazon DynamoDB#DynamoDB Thread 2'),
'ReplyDateTime' => array('S' => $sevenDaysAgo),
'Message' => array('S' => 'DynamoDB Thread 2 Reply 2 text'),
'PostedBy' => array('S' => 'User A')
)
)
),
array(
'PutRequest' => array(
'Item' => array(
'Id' => array('S' => 'Amazon DynamoDB#DynamoDB Thread 2'),
'ReplyDateTime' => array('S' => $oneDayAgo),
'Message' => array('S' => 'DynamoDB Thread 2 Reply 1 text'),
'PostedBy' => array('S' => 'User A')
)
)
)
),
)
));
echo "done." . PHP_EOL;