Skip to content

Commit 5245c66

Browse files
committed
[fix] update api vsn; readability; logic cleanup for instance states; fix region resolution
1 parent 27a67b7 commit 5245c66

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var AWS = require('aws-sdk');
2+
AWS.config.update({region: 'us-east-1'});
23
var _ = require('underscore');
3-
var ec2 = new AWS.EC2({ apiVersion: '2016-09-15' });
4-
AWS.config.region = 'us-east-1';
4+
var ec2 = new AWS.EC2({ apiVersion: '2016-11-15' });
55

66
exports.handler = (event, context, callback) => {
77
console.log('Received event:', event);
@@ -26,16 +26,16 @@ exports.handler = (event, context, callback) => {
2626
return;
2727
}
2828

29-
if (data.Reservations.length) {
29+
if (data.Reservations.length > 0) {
3030
for (r in data.Reservations) {
31-
if (data.Reservations[r].Instances.length) {
31+
if (data.Reservations[r].Instances.length > 0) {
3232
for (i in data.Reservations[r].Instances) {
3333
if (event.clickType === 'SINGLE') {
34-
if (!_.contains(['running', 'pending'], data.Reservations[r].Instances[i].State.Name)) {
34+
if (_.contains(['stopped'], data.Reservations[r].Instances[i].State.Name)) {
3535
instanceIds.push(data.Reservations[r].Instances[i].InstanceId);
3636
}
3737
} else if (event.clickType === 'DOUBLE') {
38-
if (!_.contains(['shutting-down', 'terminated', 'stopped', 'stopping'], data.Reservations[r].Instances[i].State.Name)) {
38+
if (_.contains(['running'], data.Reservations[r].Instances[i].State.Name)) {
3939
instanceIds.push(data.Reservations[r].Instances[i].InstanceId);
4040
}
4141
}
@@ -45,7 +45,7 @@ exports.handler = (event, context, callback) => {
4545
}
4646

4747
i = '';
48-
if (instanceIds.length) {
48+
if (instanceIds.length > 0) {
4949
if (event.clickType === 'SINGLE') {
5050
ec2.startInstances({ InstanceIds: instanceIds }, function(err, data) {
5151
if (!err) {

0 commit comments

Comments
 (0)