-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
41 lines (37 loc) · 1.1 KB
/
utils.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
module.exports = {
createGlobalTable: async (client, tableName, regions) => {
const {
GlobalTableDescription: { GlobalTableName, GlobalTableArn }
} = await client
.createGlobalTable({
GlobalTableName: tableName,
ReplicationGroup: regions.map(r => ({
RegionName: r
}))
})
.promise();
return { GlobalTableName, GlobalTableArn };
},
updateGlobalTable: async (client, tableName, addRegions, deleteRegions) => {
const addReplicas = addRegions.map(r => ({ Create: { RegionName: r } }));
const deleteReplicas = deleteRegions.map(r => ({
Delete: { RegionName: r }
}));
return client
.updateGlobalTable({
GlobalTableName: tableName,
ReplicaUpdates: [...addReplicas, ...deleteReplicas]
})
.promise();
},
getDeployedRegions: async (client, tableName) => {
const { GlobalTableDescription } = await client
.describeGlobalTable({
GlobalTableName: tableName
})
.promise();
return GlobalTableDescription.ReplicationGroup.map(
rg => rg.RegionName
).sort();
}
};