forked from soketi/soketi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.dynamodb-schema.js
82 lines (77 loc) · 2.2 KB
/
.dynamodb-schema.js
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
const AWS = require('aws-sdk');
let ddb = new AWS.DynamoDB({
apiVersion: '2012-08-10',
region: 'us-east-1',
endpoint: 'http://127.0.0.1:8000',
});
let createRecord = () => {
const params = {
TableName: 'apps',
Item: {
AppId: { S: 'app-id' },
AppKey: { S: 'app-key' },
AppSecret: { S: 'app-secret' },
MaxConnections: { N: '-1' },
EnableClientMessages: { B: 'false' },
Enabled: { B: 'true' },
MaxBackendEventsPerSecond: { N: '-1' },
MaxClientEventsPerSecond: { N: '-1' },
MaxReadRequestsPerSecond: { N: '-1' },
Webhooks: { S: '[]', },
},
};
return ddb.putItem(params).promise().then(() => {
console.log('Record created.');
}).catch(err => {
console.error(err);
console.log('Record already existent.');
});
};
ddb.describeTable({ TableName: 'apps' }).promise().then((result) => {
createRecord();
}).catch(err => {
console.error(err);
ddb.createTable({
TableName: 'apps',
AttributeDefinitions: [
{
AttributeName: 'AppId',
AttributeType: 'S',
},
{
AttributeName: 'AppKey',
AttributeType: 'S',
},
],
KeySchema: [{
AttributeName: 'AppId',
KeyType: 'HASH',
}],
GlobalSecondaryIndexes: [{
IndexName: 'AppKeyIndex',
KeySchema: [{
AttributeName: 'AppKey',
KeyType: 'HASH',
}],
Projection: {
ProjectionType: 'ALL',
},
ProvisionedThroughput: {
ReadCapacityUnits: 100,
WriteCapacityUnits: 100,
},
}],
StreamSpecification: {
StreamEnabled: false,
},
ProvisionedThroughput: {
ReadCapacityUnits: 100,
WriteCapacityUnits: 100,
},
}).promise().then(() => {
console.log('Table created.');
}).then(createRecord).catch((err) => {
console.error(err);
console.log('Table already existent.');
});
});