/// <summary> /// Adds new instances to the load balancer. /// Once the instance is registered, it starts receiving traffic and requests from the load balancer. /// Any instance that is not in any of the Availability Zones registered for the load balancer will be moved to the OutOfService state. /// It will move to the InService state when the Availability Zone is added to 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 registered 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> RegisterInstances(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); RegisterInstancesWithLoadBalancerRequest request = new RegisterInstancesWithLoadBalancerRequest(); request.LoadBalancerName = loadBalancer; foreach (string instance in instances) { request.Instances.Add(new Instance(instance)); } //Check Response RegisterInstancesWithLoadBalancerResponse response = await client.RegisterInstancesWithLoadBalancerAsync(request, cancellationToken); if (response.HttpStatusCode == HttpStatusCode.OK) { _Log.Verbose("Successfully registered instances '{0}'", string.Join(",", instances)); return(true); } else { _Log.Error("Failed to register instances '{0}'", string.Join(",", instances)); return(false); } }