I have a javascript and I'm trying to print the names of all my alarms in AWS cloudwatch, ie "jeisld-k-wialckei33k-High-CPU-Utilization, ajikh-q-m98k145k-High-Disk-Writes"
etc.
My code:
//configure AWS region/securities
var cw = new AWS.CloudWatch();
var alarms = cw.describeAlarms();
for (var i = 0; i < alarms.length; i ++) {
console.log(alarms[i]);
However this doesn't print anything at all. Is this the correct way to get the names of all my alarms?
EDIT: console.log(alarms)
prints [object Object]
Try this
var cloudwatch = new AWS.CloudWatch();
cloudwatch.deleteAlarms(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else showAlarms(data); // successful response
});
function showAlarms(data){
for (var i=0; i<data.MetricAlarms.length; i++){
console.log(data.MetricAlarms[i]. AlarmName);
}
}
If that doesn't work, you can loop through the object to see how it is structured, which might give you a sense of what you are working with.
function showAlarms(data){
for (var item in data) {
console.log(item);
for (var sub in item) {
console.log('>:'sub);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.