-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·41 lines (34 loc) · 1008 Bytes
/
index.js
File metadata and controls
executable file
·41 lines (34 loc) · 1008 Bytes
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
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const root = path.resolve(__dirname, '.dynamodb');
const libFolder = path.resolve(root, 'DynamoDBLocal_lib');
const jarFile = path.resolve(root, 'DynamoDBLocal.jar');
module.exports = (port = 8000, dataPath, delayTransientStatuses) => {
// Make sure the jar files have been downloaded
if (!fs.existsSync(jarFile)) {
throw new Error(`AWS DynamoDB executable is not available at ${jarFile}`);
}
const args = [
`-Djava.library.path-=${libFolder}`,
'-jar', jarFile,
'-sharedDb',
'-port', port,
];
if (dataPath) {
args.push('-dbPath');
args.push(dataPath);
} else {
args.push('-inMemory');
}
if (delayTransientStatuses) {
args.push('-delayTransientStatuses');
}
const dynamoDB = spawn('java', args, {
stdio: ['inherit', 'inherit', 'inherit'],
});
// Return a method to kill the spawned process
return () => {
dynamoDB.kill();
};
};