-
Notifications
You must be signed in to change notification settings - Fork 99
/
disable_cloudwatch_alarms.js
52 lines (46 loc) · 1.51 KB
/
disable_cloudwatch_alarms.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
46
47
48
49
50
51
52
const awsConfigHelper = require('./util/awsConfigHelper');
const wait = require('./util/wait');
const AWS = require('aws-sdk');
const cli = require('cli');
const cliArgs = cli.parse({
region: ['r', 'AWS region', 'string'],
filterName: ['f', 'Pass filter name to filter Lambda functions', 'string'],
prefix: ['pf', 'Pass fix', 'string']
});
console.log("test");
if (!cliArgs.region || ! cliArgs.prefix) {
cli.getUsage();
}
let isCompleted = false;
let nextToken = undefined;
async function disableCloudWatchAlarm() {
await awsConfigHelper.updateConfig(cliArgs.region);
const cloudwatch = new AWS.CloudWatch();
while (!isCompleted) {
try {
const response = await cloudwatch.describeAlarms({
AlarmNamePrefix: prefix,
NextToken: nextToken
}).promise();
if (response.MetricAlarms) {
let alarmNames = response.MetricAlarms.map((metricAlarm) => {
return metricAlarm.AlarmName
});
await cloudwatch.disableAlarmActions({
AlarmNames: [alarmNames]
}).promise();
nextToken = response.NextToken;
isCompleted = !nextToken;
} else {
isCompleted = true;
}
} catch (error) {
if (error.code === 'ThrottlingException') {
await wait(2000);
} else {
throw error;
}
}
}
}
disableCloudWatchAlarm();