Implementation for accessing AmazonElasticLoadBalancing. Elastic Load Balancing

Elastic Load Balancing is a cost-effective and easy to use web service to help you improve the availability and scalability of your application running on Amazon Elastic Cloud Compute (Amazon EC2). It makes it easy for you to distribute application loads between two or more EC2 instances. Elastic Load Balancing supports the growth in traffic of your application by enabling availability through redundancy.

This guide provides detailed information about Elastic Load Balancing actions, data types, and parameters that can be used for sending a query request. Query requests are HTTP or HTTPS requests that use the HTTP verb GET or POST and a query parameter named Action or Operation. Action is used throughout this documentation, although Operation is supported for backward compatibility with other AWS Query APIs.

For detailed information on constructing a query request using the actions, data types, and parameters mentioned in this guide, go to Using the Query API in the Elastic Load Balancing Developer Guide .

For detailed information about Elastic Load Balancing features and their associated actions, go to Using Elastic Load Balancing in the Elastic Load Balancing Developer Guide .

This reference guide is based on the current WSDL, which is available at:

Inheritance: AmazonWebServiceClient, IAmazonElasticLoadBalancing
示例#1
0
		protected override void OnCreate (Bundle bundle)
		{
			const string ACCESS_KEY = "";
			const string SECRET_KEY = "";
			AmazonElasticLoadBalancingClient sLBClient = new AmazonElasticLoadBalancingClient(ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.USEast1);

			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Get our button from the layout resource,
			// and attach an event to it
			Button button = FindViewById<Button> (Resource.Id.myButton);
			
			button.Click += delegate {
				var request = new Amazon.ElasticLoadBalancing.Model.CreateLoadBalancerRequest ("newLoadBalancer");
				request.AvailabilityZones = new System.Collections.Generic.List<string>{ "us-east-1b", "us-east-1c" };
				var listener = new Amazon.ElasticLoadBalancing.Model.Listener ("HTTP", 80, 45);
				request.Listeners = new System.Collections.Generic.List<Amazon.ElasticLoadBalancing.Model.Listener>{ listener };

				var response = sLBClient.CreateLoadBalancer (request);
				var status   = FindViewById<EditText>(Resource.Id.status);
				status.Text = String.Format ("Load balancer {0} was created.", response.DNSName);
			};
		}
 /// <summary>
 /// Load elastic load balancers to view model with AWS data based on region selected and EC2 classic/vpc
 /// </summary>
 private void LoadElasticLoadBalancers(AmazonElasticLoadBalancingClient elbClient)
 {
     try
     {
         DescribeLoadBalancersRequest elbreq = new DescribeLoadBalancersRequest();
         DescribeLoadBalancersResponse elbresp = elbClient.DescribeLoadBalancers(elbreq);
         Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
         {
             vm.LoadBalancers.Clear();
         }));
         foreach (LoadBalancerDescription lbd in elbresp.DescribeLoadBalancersResult.LoadBalancerDescriptions)
         {
             if (vm.IsVpc)
             {
                 if (lbd.VPCId != null && vm.SelectedVpc != null && lbd.VPCId == vm.SelectedVpc.VPC.VpcId)
                 {
                     Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                     {
                         vm.LoadBalancers.Add(lbd);
                     }));
                 }
             }
             else
             {
                 if (!(lbd.VPCId != null && lbd.VPCId != string.Empty && !vm.IsVpc))
                 {
                     Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                     {
                         vm.LoadBalancers.Add(lbd);
                     }));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogManager.LogEntry(ex.Message);
         LogManager.LogEntry(ex.StackTrace);
         throw new DataLoadingException("Error occurred loading elastic load balancers for region and environment type");
     }
 }
        /// <summary>
        /// Creates AWS Elastic Load Balancing client
        /// </summary>
        /// <returns>AmazonElasticLoadBalancingClient</returns>
        private AmazonElasticLoadBalancingClient GetElbClient()
        {
            if (vm.Region == null)
            {
                throw new InvalidRegionException("No region defined when creating elastic load balancing client");
            }

            AmazonElasticLoadBalancingConfig config = new AmazonElasticLoadBalancingConfig();
            config.ServiceURL = vm.Region.ElbUrl;

            AmazonElasticLoadBalancingClient client = new AmazonElasticLoadBalancingClient(config);

            return client;
        }