-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateTable.js
More file actions
98 lines (96 loc) · 3.82 KB
/
CreateTable.js
File metadata and controls
98 lines (96 loc) · 3.82 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
/* https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property */
/* ===================== CreateTable ===================== */
var params = {
TableName: 'table_name',
KeySchema: [ // The type of of schema. Must start with a HASH type, with an optional second RANGE.
{ // Required HASH type attribute
AttributeName: 'hash_key_attribute_name',
KeyType: 'HASH',
},
{ // Optional RANGE key type for HASH + RANGE tables
AttributeName: 'range_key_attribute_name',
KeyType: 'RANGE',
}
],
AttributeDefinitions: [ // The names and types of all primary and index key attributes only
{
AttributeName: 'hash_key_attribute_name',
AttributeType: 'S', // (S | N | B) for string, number, binary
},
{
AttributeName: 'range_key_attribute_name',
AttributeType: 'S', // (S | N | B) for string, number, binary
},
{
AttributeName: 'index_hash_key_attribute_name_1',
AttributeType: 'S', // (S | N | B) for string, number, binary
},
{
AttributeName: 'index_range_key_attribute_name_1',
AttributeType: 'S', // (S | N | B) for string, number, binary
},
{
AttributeName: 'index_range_key_attribute_name_2',
AttributeType: 'S', // (S | N | B) for string, number, binary
},
// ... more attributes ...
],
ProvisionedThroughput: { // required provisioned throughput for the table
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
GlobalSecondaryIndexes: [ // optional (list of GlobalSecondaryIndex)
{
IndexName: 'index_name_1',
KeySchema: [
{ // Required HASH type attribute
AttributeName: 'index_hash_key_attribute_name_1',
KeyType: 'HASH',
},
{ // Optional RANGE key type for HASH + RANGE secondary indexes
AttributeName: 'index_range_key_attribute_name_1',
KeyType: 'RANGE',
}
],
Projection: { // attributes to project into the index
ProjectionType: 'INCLUDE', // (ALL | KEYS_ONLY | INCLUDE)
NonKeyAttributes: [ // required / allowed only for INCLUDE
'attribute_name_1',
// ... more attribute names ...
],
},
ProvisionedThroughput: { // throughput to provision to the index
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
},
// ... more global secondary indexes ...
],
LocalSecondaryIndexes: [ // optional (list of LocalSecondaryIndex)
{
IndexName: 'index_name_2',
KeySchema: [
{ // Required HASH type attribute - must match the table's HASH key attribute name
AttributeName: 'hash_key_attribute_name',
KeyType: 'HASH',
},
{ // alternate RANGE key attribute for the secondary index
AttributeName: 'index_range_key_attribute_name_2',
KeyType: 'RANGE',
}
],
Projection: { // required
ProjectionType: 'INCLUDE', // (ALL | KEYS_ONLY | INCLUDE)
NonKeyAttributes: [ // required / allowed only for INCLUDE
'attribute_name_1',
// ... more attribute names ...
],
},
},
// ... more local secondary indexes ...
],
};
dynamodb.createTable(params, function(err, data) {
if (err) console.error(err); // an error occurred
else console.log(data); // successful response
});