public static async Task <HealthCheck> UpsertCloudWatchHealthCheckAsync(this Route53Helper r53h, string name, string alarmName, string alarmRegion, bool inverted = false, InsufficientDataHealthStatus insufficientDataHealthStatus = null, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken)) { var hc = await r53h.GetHealthCheckAsync(name, throwIfNotFound : throwIfNotFound, cancellationToken : cancellationToken); if (hc == null) { hc = (await r53h.CreateCloudWatchHealthCheckAsync( $"{name}-{Guid.NewGuid().ToString()}", alarmName, alarmRegion, inverted, insufficientDataHealthStatus, cancellationToken)).HealthCheck; await r53h.ChangeTagsForHealthCheckAsync(hc.Id, new Tag[] { new Tag() { Key = "Name", Value = name } }); await Task.Delay(1000); //ensure record was created return(hc); } var response = await r53h.UpdateHealthCheckAsync(new UpdateHealthCheckRequest() { HealthCheckId = hc.Id, AlarmIdentifier = new AlarmIdentifier() { Name = alarmName, Region = alarmRegion, }, Inverted = inverted, InsufficientDataHealthStatus = insufficientDataHealthStatus ?? InsufficientDataHealthStatus.Unhealthy }, cancellationToken); await Task.Delay(1000); //ensure record was updated return(response.HealthCheck); }
public Task <CreateHealthCheckResponse> CreateCloudWatchHealthCheckAsync( string name, string alarmName, string alarmRegion, bool inverted = false, InsufficientDataHealthStatus insufficientDataHealthStatus = null, CancellationToken cancellationToken = default(CancellationToken)) => _client.CreateHealthCheckAsync(new CreateHealthCheckRequest() { CallerReference = name, HealthCheckConfig = new HealthCheckConfig() { AlarmIdentifier = new AlarmIdentifier() { Name = alarmName, Region = alarmRegion }, Inverted = inverted, InsufficientDataHealthStatus = insufficientDataHealthStatus ?? InsufficientDataHealthStatus.Unhealthy, Type = HealthCheckType.CLOUDWATCH_METRIC, } }, cancellationToken).EnsureAnyStatusCodeAsync(System.Net.HttpStatusCode.OK, System.Net.HttpStatusCode.Created);