-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpdebug.php
More file actions
102 lines (79 loc) · 1.88 KB
/
phpdebug.php
File metadata and controls
102 lines (79 loc) · 1.88 KB
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
<?php
require 'vendor/autoload.php';
date_default_timezone_set('UTC');
use Aws\DynamoDb\Exception\DynamoDbException;
use Aws\DynamoDb\Marshaler;
$sdk = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => array(
'key' => 'AKIAIL2MKD4OL52QC2OA',
'secret' => '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',
)
]);
$dynamodb = $sdk->createDynamoDb();
$params = [
'TableName' => 'Movies',
'KeySchema' => [
[
'AttributeName' => 'year',
'KeyType' => 'HASH' //Partition key
],
[
'AttributeName' => 'title',
'KeyType' => 'RANGE' //Sort key
]
],
'AttributeDefinitions' => [
[
'AttributeName' => 'year',
'AttributeType' => 'N'
],
[
'AttributeName' => 'title',
'AttributeType' => 'S'
],
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 10
]
];
$marshaler = new Marshaler();
$tableName = 'Movies';
$year = 2015;
$title = 'The Big New Movie';
$item = $marshaler->marshalJson('
{
"year": ' . $year . ',
"title": "' . $title . '",
"info": {
"plot": "' . hash("sha256",$title) . '",
"rating": 4
}
}
');
$params = [
'TableName' => 'Movies',
'Item' => $item
];
$key = $marshaler->marshalJson('
{
"year": ' . $year . ',
"title": "' . $title . '"
}
');
$params1 = [
'TableName' => 'Movies',
'Key' => $key
];
try {
$result = $dynamodb->putItem($params);
echo "Added item: .$result. "-" . $title.\n";
$result = $dynamodb->getItem($params1);
print_r(hash("sha256",$result["Item"]["info"]["M"]["plot"][S]));
} catch (DynamoDbException $e) {
echo "Unable to add item:\n";
echo $e->getMessage() . "\n";
}
?>