From 0cf2779dc41484f6f38333c3ef4367f4e61427f4 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 22 May 2018 17:29:45 -0500 Subject: [PATCH] Filter instances to Pending or Running --- Chaosfile.json | 4 ++++ lambda/index.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Chaosfile.json b/Chaosfile.json index 4ff72fe..e78f548 100644 --- a/Chaosfile.json +++ b/Chaosfile.json @@ -11,6 +11,10 @@ "value": "true" } ], + "stateFilter":[ + "pending", + "running" + ], "slackWebhook": [ { "channel": "#random", diff --git a/lambda/index.js b/lambda/index.js index 317f0fe..9ff7bfa 100755 --- a/lambda/index.js +++ b/lambda/index.js @@ -12,15 +12,28 @@ exports.handler = function(event, context) { console.log('Chaos Llama starting up'); if (llamaConfig.probability) { - if (randomIntFromInterval(1,100) >= llamaConfig.probability && llamaConfig.probability != 100) { + if (randomIntFromInterval(1,100) > llamaConfig.probability) { console.log('Probability says it is not chaos time'); return context.done(null,null); } } +let params = {}; + +if(llamaConfig.stateFilter && llamaConfig.stateFilter.length > 0){ + params = { + Filters: [ + { + Name: 'instance-state-name', + Values: llamaConfig.stateFilter + }, + ] + }; +} + var ec2 = new AWS.EC2(); -ec2.describeInstances(function(err, data) { +ec2.describeInstances(params, function(err, data) { if (err) { return context.done(err, null); }