-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell.js
45 lines (39 loc) · 1.02 KB
/
shell.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
aws = require('aws-sdk')
require('./dynamodb-mongostyle')
var argv = require('minimist')(process.argv.slice(2));
if (argv.help) {
console.log("node shell.js [--region <region>] [--profile <profile>] [--key <key>] [--secret <secret>] [--tableprefix <tableprefix>]");
process.exit();
}
let config = {
region: argv.region ? argv.region : 'us-east-1'
}
if (argv.profile) {
config.profile = argv.profile;
}
if (argv.key) {
config.accessKeyId = argv.key;
}
if (argv.secret) {
config.secretAccessKey = argv.secret;
}
aws.config.update(config);
let dynamoConfig = {};
if (argv.endpoint) {
dynamoConfig.endpoint = new aws.Endpoint(argv.endpoint);
}
dynamodb = new aws.DynamoDB(dynamoConfig);
db = {};
dynamodb.listTables(function(err, data) {
if (err) {
console.error(err);
} else {
data.TableNames.forEach(function(table) {
db[table] = wrapTableFunctions(table);
if (argv.tableprefix) {
db[table.replace(argv.tableprefix, '')] = wrapTableFunctions(table);
}
});
}
});
require('repl').start({ignoreUndefined: true})