public static async Task <DeleteAlarmsResponse> DeleteMetricAlarmAsync(this CloudWatchHelper cwh, string name, bool throwIfNotFound, CancellationToken cancellationToken = default(CancellationToken)) { var alarms = await cwh.ListMetricAlarmsAsync(alarmNamePrefix : name, cancellationToken : cancellationToken); var alarm = alarms.SingleOrDefault(x => x.AlarmName == name); if (throwIfNotFound && alarm == null) { throw new Exception($"MetricAlarm with name: {name} was not found and can't be deleted."); } if (alarm == null) { return new DeleteAlarmsResponse() { HttpStatusCode = System.Net.HttpStatusCode.NotFound } } ; return(await cwh.DeleteAlarmAsync(alarm.AlarmName, cancellationToken)); }
public static async Task <MetricAlarm> GetMetricAlarmAsync(this CloudWatchHelper cwh, string name, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken)) { var alarms = await cwh.ListMetricAlarmsAsync(alarmNamePrefix : name, cancellationToken : cancellationToken); var alarm = alarms.SingleOrDefault(x => x.AlarmName == name); if (throwIfNotFound && alarm == null) { throw new Exception($"MetricAlarm with name: {name} was not found."); } return(alarm); }