Skip to content

Commit 630f47c

Browse files
committed
0.0.3 describe-instances, options
1 parent fb61692 commit 630f47c

4 files changed

Lines changed: 113 additions & 45 deletions

File tree

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ With promise
2626

2727
```js
2828
var awsCli = new AwsCli({
29-
aws_access_key_id: 'PUTVALUEHERE',
29+
aws_access_key_id: 'PUTVALUEHERE',
3030
aws_secret_access_key: 'abcdefPUTVALUEHERE',
3131
});
3232

@@ -80,14 +80,32 @@ awsCli.command('iam list-users', function (err, data) {
8080

8181
```
8282

83-
* ??
83+
* describe-instances
8484

8585
```js
86-
awsCli.command('??').then(function (data) {
86+
awsCli.command('ec2 describe-instances --instance-ids i-789b3ba7').then(function (data) {
8787
console.log('data = ', data);
8888
});
8989

90+
91+
//data = { command: 'aws ec2 describe-instances --instance-ids i-789b3ba7 ',
92+
// raw: '["{\\n \\"Reservations\\": [\\n {\\n \\"OwnerId\\": \\"031641171132\\", \\n \\"ReservationId\\": \\"r-a48ad878\\", \\n \\"Groups\\": [], \\n \\"Instances\\": [\\n {\\n
93+
// \\"Monitoring\\": {\\n \\"State\\": \\"disabled\\"\\n }, \\n
94+
// \\"PublicDnsName\\": \\"ec2-52-64-166-221.ap-southeast-2.compute.amazonaws.com\\", \\n \\"State\\": {\\n
95+
// ...
96+
97+
```
98+
or with options
99+
100+
```js
101+
awsCli.command('ec2 describe-instances', , { 'instance-ids': instance_id }).then(function (data) {
102+
console.log('data = ', data);
103+
});
104+
105+
106+
90107
//data = { command: 'aws ?? ',
91108

92109
```
93110

111+

lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ AwsCli.prototype.command = function (command, options, callback) {
3434
var exec_command = 'aws ';
3535

3636
if (!callback) {
37-
callback = options;
38-
options = null;
37+
if (typeof options === 'function') {
38+
callback = options;
39+
options = null;
40+
}
3941
}
4042

4143
return Promise.resolve().then(function () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-cli-js",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A node.js wrapper for the aws command line interface",
55
"main": "lib/index.js",
66
"scripts": {

test/index.js

Lines changed: 87 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,88 @@ var util = require('util');
2424
var config = require('../my_config.json');
2525

2626

27-
describe('AwsCli', function () {
28-
29-
it('should merge opts', function () {
30-
var awsCli = new AwsCli({ a: 'a' });
31-
assert.isNotNull(awsCli);
32-
assert.equal(awsCli.a, 'a');
33-
//console.log('awsCli', awsCli);
34-
});
35-
36-
37-
it('command iam list-users should pass', function (done) {
27+
//describe('AwsCli run without modifications', function () {
28+
29+
// it('should merge opts', function () {
30+
// var awsCli = new AwsCli({ a: 'a' });
31+
// assert.isNotNull(awsCli);
32+
// assert.equal(awsCli.a, 'a');
33+
// //console.log('awsCli', awsCli);
34+
// });
35+
36+
37+
// it('command iam list-users should pass', function (done) {
38+
// this.timeout(1 * 60 * 1000);//1 minute
39+
40+
// var awsCli = new AwsCli({
41+
// aws_access_key_id: config.aws.accessKeyId,
42+
// aws_secret_access_key: config.aws.secretAccessKey
43+
// //cwd: 'path to current working directory'
44+
// });
45+
46+
// assert.isNotNull(awsCli);
47+
// var failed = false;
48+
// var err = null;
49+
// awsCli.command('iam list-users').then(function (data) {
50+
// //console.log('data = ', util.inspect(data, {depth: 10}));
51+
// assert.isNotNull(data);
52+
// }).finally(function () {
53+
// //console.log('finally ');
54+
// assert.isFalse(failed);
55+
// assert.isNull(err);
56+
// done();
57+
// });
58+
// });
59+
60+
// it('command iam list-users should pass with callback', function (done) {
61+
// this.timeout(1 * 60 * 1000);//1 minute
62+
63+
// var awsCli = new AwsCli({
64+
// aws_access_key_id: config.aws.accessKeyId,
65+
// aws_secret_access_key: config.aws.secretAccessKey
66+
// //cwd: 'path to current working directory'
67+
// });
68+
69+
// assert.isNotNull(awsCli);
70+
// var failed = false;
71+
// var err = null;
72+
// awsCli.command('iam list-users', function (err, data) {
73+
// //console.log('data = ', util.inspect(data, { depth: 10 }));
74+
// assert.isNotNull(data);
75+
// done();
76+
// });
77+
// });
78+
79+
// it('command aim2 should fail', function (done) {
80+
// var awsCli = new AwsCli();
81+
// assert.isNotNull(awsCli);
82+
// var failed = false;
83+
// var err = null;
84+
// awsCli.command('iam2 list-users').then(function (data) {
85+
// //console.log('data = ', data);
86+
// assert.isNotNull(data);
87+
// }).catch(function (error) {
88+
// assert.isNotNull(error);
89+
// err = error;
90+
// failed = true;
91+
// //console.log('error = ', error);
92+
// }).finally(function () {
93+
// //console.log('finally ');
94+
// assert.isTrue(failed);
95+
// assert.isNotNull(err);
96+
// done();
97+
// });
98+
// });
99+
100+
101+
//});
102+
103+
104+
105+
describe('AwsCli change ids', function () {
106+
var instance_id = 'i-789b3ba7';
107+
108+
it('ec2 describe-instances', function (done) {
38109
this.timeout(1 * 60 * 1000);//1 minute
39110

40111
var awsCli = new AwsCli({
@@ -46,7 +117,7 @@ describe('AwsCli', function () {
46117
assert.isNotNull(awsCli);
47118
var failed = false;
48119
var err = null;
49-
awsCli.command('iam list-users').then(function (data) {
120+
awsCli.command('ec2 describe-instances --instance-ids ' + instance_id).then(function (data) {
50121
//console.log('data = ', util.inspect(data, {depth: 10}));
51122
assert.isNotNull(data);
52123
}).finally(function () {
@@ -57,7 +128,7 @@ describe('AwsCli', function () {
57128
});
58129
});
59130

60-
it('command iam list-users should pass with callback', function (done) {
131+
it('ec2 describe-instances with options', function (done) {
61132
this.timeout(1 * 60 * 1000);//1 minute
62133

63134
var awsCli = new AwsCli({
@@ -69,38 +140,15 @@ describe('AwsCli', function () {
69140
assert.isNotNull(awsCli);
70141
var failed = false;
71142
var err = null;
72-
awsCli.command('iam list-users', function (err, data) {
143+
awsCli.command('ec2 describe-instances', { 'instance-ids': instance_id }).then(function (data) {
73144
//console.log('data = ', util.inspect(data, { depth: 10 }));
74145
assert.isNotNull(data);
75-
done();
76-
});
77-
});
78-
79-
it('command aim2 should fail', function (done) {
80-
var awsCli = new AwsCli();
81-
assert.isNotNull(awsCli);
82-
var failed = false;
83-
var err = null;
84-
awsCli.command('iam2 list-users').then(function (data) {
85-
//console.log('data = ', data);
86-
assert.isNotNull(data);
87-
}).catch(function (error) {
88-
assert.isNotNull(error);
89-
err = error;
90-
failed = true;
91-
//console.log('error = ', error);
92146
}).finally(function () {
93147
//console.log('finally ');
94-
assert.isTrue(failed);
95-
assert.isNotNull(err);
148+
assert.isFalse(failed);
149+
assert.isNull(err);
96150
done();
97151
});
98152
});
99153

100154
});
101-
102-
103-
104-
105-
106-

0 commit comments

Comments
 (0)