private Amazon.ElasticLoadBalancingV2.Model.DescribeTargetHealthResponse CallAWSServiceOperation(IAmazonElasticLoadBalancingV2 client, Amazon.ElasticLoadBalancingV2.Model.DescribeTargetHealthRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Elastic Load Balancing V2", "DescribeTargetHealth"); try { #if DESKTOP return(client.DescribeTargetHealth(request)); #elif CORECLR return(client.DescribeTargetHealthAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
public async Task <Response> Handle(SNSEvent snsRequest, CancellationToken cancellationToken = default) { var request = requestFactory.CreateFromSnsEvent(snsRequest); logger.LogInformation($"Received transformed request: {JsonSerializer.Serialize(request)}"); var addresses = dnsResolver.Resolve(request.TargetDnsName).AddressList ?? new IPAddress[] { }; var targetHealthRequest = new DescribeTargetHealthRequest { TargetGroupArn = request.TargetGroupArn }; var targetHealthResponse = await elbClient.DescribeTargetHealthAsync(targetHealthRequest); logger.LogInformation($"Got target health response: {JsonSerializer.Serialize(targetHealthResponse)}"); var targetHealthDescriptions = targetHealthResponse.TargetHealthDescriptions; var healthyTargets = from target in targetHealthDescriptions where target.TargetHealth.State != TargetHealthStateEnum.Unhealthy select target.Target; var unhealthyTargets = from target in targetHealthDescriptions where target.TargetHealth.State == TargetHealthStateEnum.Unhealthy select target.Target; var newTargets = from address in addresses where healthyTargets.All(target => !IPAddress.Parse(target.Id).Equals(address)) select new TargetDescription { Id = address.ToString(), AvailabilityZone = "all", Port = 80 }; await Task.WhenAll(new Task[] { DeregisterTargets(request.TargetGroupArn, unhealthyTargets), RegisterTargets(request.TargetGroupArn, newTargets), }); return(new Response { Success = true }); }