AWS EC2 Service Discovery
The HAProxy Data Plane API scales your HAProxy Enterprise configuration to dynamically fit the current capacity of your pool of EC2 instances.
The HAProxy Data Plane API:
Regularly polls the AWS EC2 API.
Automatically creates HAProxy Enterprise backends.
Populates your HAProxy Enterprise backends with the addresses of your EC2 instances.
Minimizes reloads during scaling events thanks to the HAProxy Runtime API.

See also
Enable Service Discovery on HAProxy Enterprise
To enable service discovery, install and configure the HAProxy Data Plane API.
-
Add a section such as the following to the /etc/hapee-extras/dataplaneapi.hcl configuration file.
service_discovery { aws_regions = [ { AccessKeyID = "KAB[...]2X6" Description = "Production environment" Enabled = true IPV4Address = "private" Name = "my-disc" Region = "eu-west-3" RetryTimeout = 10 SecretAccessKey = "qjT[...]uXV" ServerSlotsBase = 10 ServerSlotsGrowthIncrement = 0 ServerSlotsGrowthType = "exponential" }, ] }
HCL configuration directive
JSON directive
Description
AccessKeyID
access_key_id
AWS Access Key ID
Description
description
Service discovery description
Enabled
enabled
true or false.
If set to false:
The Data Plane API will not update
server
sections in discoveredbackend
sections.-
Data can become outdated if:
newer EC2 instances launch, or
if an existing instance reboots with a new IPv4 address.
IPV4Address
ipv4_address
private (for the private network, reachable inside the AWS VPC) or public.
Name
name
Service discovery name
Region
region
AWS region
RetryTimeout
retry_timeout
Interval of time in seconds between the reconciliation and the following.
SecretAccessKey
secret_access_key
AWS Secret Access Key
ServerSlotsBase
server_slots_base
The minimum amount of
server
entries perbackend
section.Defaults to 10.
ServerSlotsGrowthIncrement
server_slots_growth_increment
The number of additional slots that are allocated for
server
entries if there are additional entries.Defaults to 0.
ServerSlotsGrowthType
server_slots_growth_type
Function type to implement when the number of
server
slots increases: exponential or linear.Defaults to exponential.
-
Restart the service:
$ sudo systemctl restart hapee-extras-dataplaneapi
-
Check the /etc/hapee-1.6/hapee-lb.cfg file.
A new backend section displays.
The name of the new backend comprises the following parts:
aws-<AWS region>-<Service discovery name>-<HAProxy:Service:Name tag value>-<HAProxy:Service:Port tag value>
backend aws-eu-west-3-my-disc-MyApp-80 server SRV_ONGQw 172.31.14.35:80 check weight 128 server SRV_5hi3l 127.0.0.1:80 disabled weight 128 server SRV_L2rw7 127.0.0.1:80 disabled weight 128 server SRV_pG3MX 127.0.0.1:80 disabled weight 128 server SRV_9WFsc 127.0.0.1:80 disabled weight 128 server SRV_o2UU2 127.0.0.1:80 disabled weight 128 server SRV_GMuw1 127.0.0.1:80 disabled weight 128 server SRV_3Id36 127.0.0.1:80 disabled weight 128 server SRV_6Ivld 127.0.0.1:80 disabled weight 128 server SRV_jYF88 127.0.0.1:80 disabled weight 128
This backend may only have several servers enabled out of the total number of servers specified by the
ServerSlotsBase
directive.When you register more instances of the same service, HAProxy Enterprise fills in disabled server slots. You can thus scale up or down without a reload, in most cases.
-
Edit the new backend as needed.
For example, you can specify a load-balancing algorithm.
Configure a
frontend
section that routes traffic to this backend pool of servers.
See also
Next up
Consul Service Discovery