/// <summary> /// Removes instances from the load balancer. Once the instance is deregistered, it will stop receiving traffic from the load balancer. /// </summary> /// <param name="loadBalancer">The name associated with the load balancer.</param> /// <param name="instances">A list of instance IDs that should be deregistered with the load balancer.</param> /// <param name="settings">The <see cref="LoadBalancingSettings"/> used during the request to AWS.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async Task <bool> DeregisterInstances(string loadBalancer, IList <string> instances, LoadBalancingSettings settings, CancellationToken cancellationToken = default(CancellationToken)) { if (String.IsNullOrEmpty(loadBalancer)) { throw new ArgumentNullException("loadBalancer"); } if ((instances == null) || (instances.Count == 0)) { throw new ArgumentNullException("instances"); } //Create Request AmazonElasticLoadBalancingClient client = this.CreateClient(settings); DeregisterInstancesFromLoadBalancerRequest request = new DeregisterInstancesFromLoadBalancerRequest(); request.LoadBalancerName = loadBalancer; foreach (string instance in instances) { request.Instances.Add(new Instance(instance)); } //Check Response DeregisterInstancesFromLoadBalancerResponse response = await client.DeregisterInstancesFromLoadBalancerAsync(request, cancellationToken); if (response.HttpStatusCode == HttpStatusCode.OK) { _Log.Verbose("Successfully deregistered instances '{0}'", string.Join(",", instances)); return(true); } else { _Log.Error("Failed to deregister instances '{0}'", string.Join(",", instances)); return(false); } }