1
|
|
|
var params = { |
2
|
|
|
TableName: 'test_model', |
3
|
|
|
KeySchema: [ // The type of of schema. Must start with a HASH type, with an optional second RANGE. |
4
|
|
|
{ // Required HASH type attribute |
5
|
|
|
AttributeName: 'id', |
6
|
|
|
KeyType: 'HASH', |
7
|
|
|
} |
8
|
|
|
], |
9
|
|
|
AttributeDefinitions: [ // The names and types of all primary and index key attributes only |
10
|
|
|
{ |
11
|
|
|
AttributeName: 'id', |
12
|
|
|
AttributeType: 'S', // (S | N | B) for string, number, binary |
13
|
|
|
}, |
14
|
|
|
{ |
15
|
|
|
AttributeName: 'count', |
16
|
|
|
AttributeType: 'N', // (S | N | B) for string, number, binary |
17
|
|
|
} |
18
|
|
|
], |
19
|
|
|
ProvisionedThroughput: { // required provisioned throughput for the table |
20
|
|
|
ReadCapacityUnits: 1, |
21
|
|
|
WriteCapacityUnits: 1, |
22
|
|
|
}, |
23
|
|
|
GlobalSecondaryIndexes: [ // optional (list of GlobalSecondaryIndex) |
24
|
|
|
{ |
25
|
|
|
IndexName: 'count_index', |
26
|
|
|
KeySchema: [ |
27
|
|
|
{ // Required HASH type attribute |
28
|
|
|
AttributeName: 'count', |
29
|
|
|
KeyType: 'HASH', |
30
|
|
|
} |
31
|
|
|
], |
32
|
|
|
Projection: { // attributes to project into the index |
33
|
|
|
ProjectionType: 'ALL', // (ALL | KEYS_ONLY | INCLUDE) |
34
|
|
|
}, |
35
|
|
|
ProvisionedThroughput: { // throughput to provision to the index |
36
|
|
|
ReadCapacityUnits: 1, |
37
|
|
|
WriteCapacityUnits: 1, |
38
|
|
|
}, |
39
|
|
|
}, |
40
|
|
|
// ... more global secondary indexes ... |
41
|
|
|
] |
42
|
|
|
}; |
43
|
|
|
dynamodb.createTable(params, function(err, data) { |
|
|
|
|
44
|
|
|
if (err) print(err); // an error occurred |
|
|
|
|
45
|
|
|
else print(data); // successful response |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
// Table with composite keys: |
49
|
|
|
|
50
|
|
|
params = { |
51
|
|
|
TableName: 'composite_test_model', |
52
|
|
|
KeySchema: [ // The type of of schema. Must start with a HASH type, with an optional second RANGE. |
53
|
|
|
{ // Required HASH type attribute |
54
|
|
|
AttributeName: 'id', |
55
|
|
|
KeyType: 'HASH', |
56
|
|
|
}, |
57
|
|
|
{ |
58
|
|
|
AttributeName: 'id2', |
59
|
|
|
KeyType: 'RANGE', |
60
|
|
|
} |
61
|
|
|
], |
62
|
|
|
AttributeDefinitions: [ // The names and types of all primary and index key attributes only |
63
|
|
|
{ |
64
|
|
|
AttributeName: 'id', |
65
|
|
|
AttributeType: 'S', // (S | N | B) for string, number, binary |
66
|
|
|
}, |
67
|
|
|
{ |
68
|
|
|
AttributeName: 'id2', |
69
|
|
|
AttributeType: 'S', // (S | N | B) for string, number, binary |
70
|
|
|
}, |
71
|
|
|
{ |
72
|
|
|
AttributeName: 'count', |
73
|
|
|
AttributeType: 'N', // (S | N | B) for string, number, binary |
74
|
|
|
} |
75
|
|
|
], |
76
|
|
|
ProvisionedThroughput: { // required provisioned throughput for the table |
77
|
|
|
ReadCapacityUnits: 1, |
78
|
|
|
WriteCapacityUnits: 1, |
79
|
|
|
}, |
80
|
|
|
GlobalSecondaryIndexes: [ // optional (list of GlobalSecondaryIndex) |
81
|
|
|
{ |
82
|
|
|
IndexName: 'count_index', |
83
|
|
|
KeySchema: [ |
84
|
|
|
{ // Required HASH type attribute |
85
|
|
|
AttributeName: 'count', |
86
|
|
|
KeyType: 'HASH', |
87
|
|
|
} |
88
|
|
|
], |
89
|
|
|
Projection: { // attributes to project into the index |
90
|
|
|
ProjectionType: 'ALL', // (ALL | KEYS_ONLY | INCLUDE) |
91
|
|
|
}, |
92
|
|
|
ProvisionedThroughput: { // throughput to provision to the index |
93
|
|
|
ReadCapacityUnits: 1, |
94
|
|
|
WriteCapacityUnits: 1, |
95
|
|
|
}, |
96
|
|
|
}, |
97
|
|
|
{ |
98
|
|
|
IndexName: 'id_count_index', |
99
|
|
|
KeySchema: [ |
100
|
|
|
{ // Required HASH type attribute |
101
|
|
|
AttributeName: 'id', |
102
|
|
|
KeyType: 'HASH', |
103
|
|
|
}, |
104
|
|
|
{ |
105
|
|
|
AttributeName: 'count', |
106
|
|
|
KeyType: 'RANGE', |
107
|
|
|
} |
108
|
|
|
], |
109
|
|
|
Projection: { // attributes to project into the index |
110
|
|
|
ProjectionType: 'ALL', // (ALL | KEYS_ONLY | INCLUDE) |
111
|
|
|
}, |
112
|
|
|
ProvisionedThroughput: { // throughput to provision to the index |
113
|
|
|
ReadCapacityUnits: 1, |
114
|
|
|
WriteCapacityUnits: 1, |
115
|
|
|
}, |
116
|
|
|
}, |
117
|
|
|
// ... more global secondary indexes ... |
118
|
|
|
] |
119
|
|
|
}; |
120
|
|
|
|
121
|
|
|
dynamodb.createTable(params, function(err, data) { |
122
|
|
|
if (err) { |
123
|
|
|
print(err); |
124
|
|
|
} else { |
125
|
|
|
print(data); |
126
|
|
|
} |
127
|
|
|
}); |
128
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.