AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Creates a Classic Load Balancer.

You can add listeners, security groups, subnets, and tags when you create your load balancer, or you can add them later using CreateLoadBalancerListeners, ApplySecurityGroupsToLoadBalancer, AttachLoadBalancerToSubnets, and AddTags.

To describe your current load balancers, see DescribeLoadBalancers. When you are finished with a load balancer, you can delete it using DeleteLoadBalancer.

You can create up to 20 load balancers per region per account. You can request an increase for the number of load balancers for your account. For more information, see Limits for Your Classic Load Balancer in the Classic Load Balancer Guide.

Note:

For PCL this operation is only available in asynchronous form. Please refer to CreateLoadBalancerAsync.

Namespace: Amazon.ElasticLoadBalancing
Assembly: AWSSDK.ElasticLoadBalancing.dll
Version: 3.x.y.z

Syntax

C#
public abstract CreateLoadBalancerResponse CreateLoadBalancer(
         CreateLoadBalancerRequest request
)
Parameters
request
Type: Amazon.ElasticLoadBalancing.Model.CreateLoadBalancerRequest

Container for the necessary parameters to execute the CreateLoadBalancer service method.

Return Value
The response from the CreateLoadBalancer service method, as returned by ElasticLoadBalancing.

Exceptions

ExceptionCondition
CertificateNotFoundException The specified ARN does not refer to a valid SSL certificate in AWS Identity and Access Management (IAM) or AWS Certificate Manager (ACM). Note that if you recently uploaded the certificate to IAM, this error might indicate that the certificate is not fully available yet.
DuplicateAccessPointNameException The specified load balancer name already exists for this account.
DuplicateTagKeysException A tag key was specified more than once.
InvalidConfigurationRequestException The requested configuration change is not valid.
InvalidSchemeException The specified value for the schema is not valid. You can only specify a scheme for load balancers in a VPC.
InvalidSecurityGroupException One or more of the specified security groups do not exist.
InvalidSubnetException The specified VPC has no associated Internet gateway.
SubnetNotFoundException One or more of the specified subnets do not exist.
TooManyAccessPointsException The quota for the number of load balancers has been reached.
TooManyTagsException The quota for the number of tags that can be assigned to a load balancer has been reached.
UnsupportedProtocolException The specified protocol or signature version is not supported.

Examples

This example creates a load balancer with an HTTP listener in a VPC.

To create an HTTP load balancer in a VPC


var response = client.CreateLoadBalancer(new CreateLoadBalancerRequest 
{
    Listeners = new List {
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 80,
            Protocol = "HTTP"
        }
    },
    LoadBalancerName = "my-load-balancer",
    SecurityGroups = new List {
        "sg-a61988c3"
    },
    Subnets = new List {
        "subnet-15aaab61"
    }
});

string dnsName = response.DNSName;

            

This example creates a load balancer with an HTTP listener in EC2-Classic.

To create an HTTP load balancer in EC2-Classic


var response = client.CreateLoadBalancer(new CreateLoadBalancerRequest 
{
    AvailabilityZones = new List {
        "us-west-2a"
    },
    Listeners = new List {
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 80,
            Protocol = "HTTP"
        }
    },
    LoadBalancerName = "my-load-balancer"
});

string dnsName = response.DNSName;

            

This example creates a load balancer with an HTTPS listener in a VPC.

To create an HTTPS load balancer in a VPC


var response = client.CreateLoadBalancer(new CreateLoadBalancerRequest 
{
    Listeners = new List {
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 80,
            Protocol = "HTTP"
        },
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 443,
            Protocol = "HTTPS",
            SSLCertificateId = "arn:aws:iam::123456789012:server-certificate/my-server-cert"
        }
    },
    LoadBalancerName = "my-load-balancer",
    SecurityGroups = new List {
        "sg-a61988c3"
    },
    Subnets = new List {
        "subnet-15aaab61"
    }
});

string dnsName = response.DNSName;

            

This example creates a load balancer with an HTTPS listener in EC2-Classic.

To create an HTTPS load balancer in EC2-Classic


var response = client.CreateLoadBalancer(new CreateLoadBalancerRequest 
{
    AvailabilityZones = new List {
        "us-west-2a"
    },
    Listeners = new List {
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 80,
            Protocol = "HTTP"
        },
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 443,
            Protocol = "HTTPS",
            SSLCertificateId = "arn:aws:iam::123456789012:server-certificate/my-server-cert"
        }
    },
    LoadBalancerName = "my-load-balancer"
});

string dnsName = response.DNSName;

            

This example creates an internal load balancer with an HTTP listener in a VPC.

To create an internal load balancer


var response = client.CreateLoadBalancer(new CreateLoadBalancerRequest 
{
    Listeners = new List {
        new Listener {
            InstancePort = 80,
            InstanceProtocol = "HTTP",
            LoadBalancerPort = 80,
            Protocol = "HTTP"
        }
    },
    LoadBalancerName = "my-load-balancer",
    Scheme = "internal",
    SecurityGroups = new List {
        "sg-a61988c3"
    },
    Subnets = new List {
        "subnet-15aaab61"
    }
});

string dnsName = response.DNSName;

            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms

See Also