Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:31:31+00:00 2026-06-03T00:31:31+00:00

as part of a project i need to create a new load balancer on

  • 0

as part of a project i need to create a new load balancer on amazon AWS.
i need to do it using the java sdk

how can i set the load balancer up using code?

here is what i tried so far without success.

//create load balancer
        CreateLoadBalancerRequest lbRequest = new CreateLoadBalancerRequest();
        lbRequest.setLoadBalancerName("loader");
        List<Listener> listeners = new ArrayList<Listener>(1);
        listeners.add(new Listener("HTTP", 80, 80));
        lbRequest.withAvailabilityZones(availabilityZone1,availabilityZone2);
        lbRequest.setListeners(listeners);

        CreateLoadBalancerResult lbResult=new CreateLoadBalancerResult();
        System.out.println("created load balancer loader");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:31:33+00:00Added an answer on June 3, 2026 at 12:31 am

    well finelly i got it:

    first create an elb client

    AmazonElasticLoadBalancingClient elb = new AmazonElasticLoadBalancingClient(credentials);
    

    then

    use it to initiate the request

      //create load balancer
            CreateLoadBalancerRequest lbRequest = new CreateLoadBalancerRequest();
            lbRequest.setLoadBalancerName("loader");
            List<Listener> listeners = new ArrayList<Listener>(1);
            listeners.add(new Listener("HTTP", 80, 80));
            lbRequest.withAvailabilityZones(availabilityZone1,availabilityZone2);
            lbRequest.setListeners(listeners);
    
            CreateLoadBalancerResult lbResult=elb.createLoadBalancer(lbRequest);
            System.out.println("created load balancer loader");
    

    then register your instances to the Load balancer

    //get the running instances
            DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
            List<Reservation> reservations = describeInstancesRequest.getReservations();
            List<Instance> instances = new ArrayList<Instance>();
    
            for (Reservation reservation : reservations) {
                instances.addAll(reservation.getInstances());
            }
    
    
            //get instance id's
            String id;
            List instanceId=new ArrayList();
            List instanceIdString=new ArrayList();
            Iterator<Instance> iterator=instances.iterator();
            while (iterator.hasNext())
            {
                id=iterator.next().getInstanceId();
                instanceId.add(new com.amazonaws.services.elasticloadbalancing.model.Instance(id));
                instanceIdString.add(id);
            }
    
    
            //register the instances to the balancer
            RegisterInstancesWithLoadBalancerRequest register =new RegisterInstancesWithLoadBalancerRequest();
            register.setLoadBalancerName("loader");
            register.setInstances((Collection)instanceId);
            RegisterInstancesWithLoadBalancerResult registerWithLoadBalancerResult= elb.registerInstancesWithLoadBalancer(register);
    

    and you are done…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of my project I need to use some Unamanged code dlls in
How can I create a new project that only uses the Symfony2 Console component?
As a part of my project I need to create non repeating 2 or
As part of an upcoming project at my university, I need to write a
In part of my project I need to compute orientation of a patch in
I have part of a project whereby I need to send 1 to up
I have a project that we need to set up a simple branching strategy
As part of a project I have assigned myself as a way of improving
For part of a project I'm working on I am implementing a RTPpacket where
As part of a project with a partner, we are required to provide single-sign-on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.