Creates a new LoadBalancer.
After the call has completed successfully, a new LoadBalancer is created; however, it will not
be usable until at least one instance has been registered. When the LoadBalancer creation is
completed, the client can check whether or not it is usable by using the DescribeInstanceHealth
API. The LoadBalancer is usable as soon as any registered instance is InService.
Currently, the client’s quota of LoadBalancers is limited to ten per Region.
LoadBalancer DNS names vary depending on the Region they’re created in. For LoadBalancers
created in the United States, the DNS name ends with:
- us-east-1.elb.amazonaws.com (for the US Standard Region)
- us-west-1.elb.amazonaws.com (for the Northern California Region)
For LoadBalancers created in the EU (Ireland) Region, the DNS name ends with:
- eu-west-1.elb.amazonaws.com
Access
Parameters
Parameter |
Type |
Required |
Description |
$load_balancer_name
|
string
|
Required
|
The name associated with the LoadBalancer. The name must be unique within your set of LoadBalancers. |
$listeners
|
array
|
Required
|
A list of the following tuples: LoadBalancerPort, InstancePort, and Protocol.
x - array - Optional - This represents a simple array index. Protocol - string - Required - Specifies the LoadBalancer transport protocol to use for routing - HTTP, HTTPS, TCP or SSL. This property cannot be modified for the life of the LoadBalancer.LoadBalancerPort - integer - Required - Specifies the external LoadBalancer port number. This property cannot be modified for the life of the LoadBalancer.InstanceProtocol - string - Optional - Specifies the protocol to use for routing traffic to back-end instances - HTTP, HTTPS, TCP, or SSL. This property cannot be modified for the life of the LoadBalancer. If the front-end protocol is HTTP or HTTPS, InstanceProtocol has to be at the same protocol layer, i.e., HTTP or HTTPS. Likewise, if the front-end protocol is TCP or SSL, InstanceProtocol has to be TCP or SSL. If there is another listener with the same InstancePort whose InstanceProtocol is secure, i.e., HTTPS or SSL, the listener’s InstanceProtocol has to be secure, i.e., HTTPS or SSL. If there is another listener with the same InstancePort whose InstanceProtocol is HTTP or TCP, the listener’s InstanceProtocol must be either HTTP or TCP. InstancePort - integer - Required - Specifies the TCP port on which the instance server is listening. This property cannot be modified for the life of the LoadBalancer.SSLCertificateId - string - Optional - The ARN string of the server certificate. To get the ARN of the server certificate, call the AWS Identity and Access Management UploadServerCertificate API.
|
$opt
|
array
|
Optional
|
An associative array of parameters that can have the following keys:
AvailabilityZones - string|array - Optional - A list of Availability Zones. At least one Availability Zone must be specified. Specified Availability Zones must be in the same EC2 Region as the LoadBalancer. Traffic will be equally distributed across all zones. This list can be modified after the creation of the LoadBalancer. Pass a string for a single value, or an indexed array for multiple values.Subnets - string|array - Optional - A list of subnet IDs in your VPC to attach to your LoadBalancer. Pass a string for a single value, or an indexed array for multiple values.SecurityGroups - string|array - Optional - The security groups assigned to your LoadBalancer within your VPC. Pass a string for a single value, or an indexed array for multiple values.Scheme - string - Optional - The type of a LoadBalancer. This option is only available for LoadBalancers attached to a Amazon VPC. By default, Elastic Load Balancer creates an internet-facing load balancer with publicly resolvable DNS name that resolves to public IP addresses. Specify the value internal for this option to create an internal load balancer with a DNS name that resolves to private IP addresses.curlopts - array - Optional - A set of values to pass directly into curl_setopt() , where the key is a pre-defined CURLOPT_* constant.returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests. |
Returns
Examples
Create a new load balancer and attach to a subnet.
To set up a new load balancer for one or more instances, you need to:
- Create a new load balancer with
create_load_balancer()
.
- Register one or more EC2 instances with the load balancer using
register_instances_with_load_balancer()
.
$elb = new AmazonELB();
$response = $elb->create_load_balancer('my-load-balancer', array(
array(
'Protocol' => 'HTTP',
'InstancePort' => 80,
'LoadBalancerPort' => 80
)
), array(
'AvailabilityZones' => 'us-east-1a'
));
// Success?
var_dump($response->isOK());
Result:
bool(true)
Create a new load balancer and attach to a subnet.
To set up a new load balancer for one or more instances, you need to:
- Create a new load balancer with
create_load_balancer()
.
- Register one or more EC2 instances with the load balancer using
register_instances_with_load_balancer()
.
$elb = new AmazonELB();
$ec2 = new AmazonEC2();
// Lookup the ID for the "default" security group
$response = $ec2->describe_security_groups(array(
'GroupName' => 'default'
));
$security_group = (string) $response->body->securityGroupInfo->item->groupId;
$response = $elb->create_load_balancer('my-load-balancer2', array(
array(
'Protocol' => 'HTTP',
'InstancePort' => 80,
'LoadBalancerPort' => 80
)
), array(
'Subnets' => 'subnet-2d78d544',
'SecurityGroups' => $security_group
));
// Success?
var_dump($response->isOK());
Result:
bool(true)
Changelog
Version |
Description |
1.5
|
The CreateLoadBalancer operation introduced backwards-incompatible changes in the 2011-11-15 API release. The AvailabilityZones parameter is no longer required. |
Related Methods
Source
Method defined in services/elb.class.php | Toggle source view (39 lines) | View on GitHub
public function create_load_balancer($load_balancer_name, $listeners, $opt = null)
{
if (!$opt) $opt = array();
$opt['LoadBalancerName'] = $load_balancer_name;
// Required list + map
$opt = array_merge($opt, CFComplexType::map(array(
'Listeners' => (is_array($listeners) ? $listeners : array($listeners))
), 'member'));
// Optional list (non-map)
if (isset($opt['AvailabilityZones']))
{
$opt = array_merge($opt, CFComplexType::map(array(
'AvailabilityZones' => (is_array($opt['AvailabilityZones']) ? $opt['AvailabilityZones'] : array($opt['AvailabilityZones']))
), 'member'));
unset($opt['AvailabilityZones']);
}
// Optional list (non-map)
if (isset($opt['Subnets']))
{
$opt = array_merge($opt, CFComplexType::map(array(
'Subnets' => (is_array($opt['Subnets']) ? $opt['Subnets'] : array($opt['Subnets']))
), 'member'));
unset($opt['Subnets']);
}
// Optional list (non-map)
if (isset($opt['SecurityGroups']))
{
$opt = array_merge($opt, CFComplexType::map(array(
'SecurityGroups' => (is_array($opt['SecurityGroups']) ? $opt['SecurityGroups'] : array($opt['SecurityGroups']))
), 'member'));
unset($opt['SecurityGroups']);
}
return $this->authenticate('CreateLoadBalancer', $opt);
}