Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active August 2, 2021 15:10
Show Gist options
  • Save haproxytechblog/50cea2b61041b748b80a2f92fd90c37d to your computer and use it in GitHub Desktop.
Save haproxytechblog/50cea2b61041b748b80a2f92fd90c37d to your computer and use it in GitHub Desktop.
AWS EC2 Service Discovery with HAProxy
$ ssh -i ~/MyKeyPair.pem ubuntu@<public_ip_of_instance>
$ sudo nano /etc/hapee-2.2/hapee-lb.cfg
userlist hapee-dataplaneapi
user admin insecure-password adminpwd
$ sudo apt install -y whois
$ mkpasswd -m sha-256 mypassword
# encrypted password:
# $5$sj7aJ5nSSX1693nT$IVBQYoexyD2qaTeMOTym6evFqHRN9289gIw9UyAHKp5
userlist hapee-dataplaneapi
user admin password $5$sj7aJ5nSSX1693nT$IVBQYoexyD2qaTeMOTym6evFqHRN9289gIw9UyAHKp5
$ sudo systemctl restart hapee-2.2-lb
$ curl -H 'Content-Type: application/json' -u admin:adminpwd -d '{
"access_key_id":"AKIAXXXXXXXXXXXXXXXX",
"secret_access_key":"ZGSNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"description":"AWS EC2 Production Environment",
"enabled":true,
"ipv4_address":"private",
"name":"www",
"region":"us-east-1",
"retry_timeout":10}' http://127.0.0.1:5555/v2/service_discovery/aws
{
"access_key_id": "AKIAXXXXXXXXXXXXXXXX",
"allowlist": null,
"denylist": null,
"description": "AWS EC2 Production Environment",
"enabled": true,
"id": "ffdf439e-a947-4401-a0db-6f7cb3ac3c40",
"ipv4_address": "private",
"name": "www",
"region": "us-east-1",
"retry_timeout": 10,
"secret_access_key": "ZGSNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"server_slots_base": 10,
"server_slots_growth_type": "exponential"
}
backend aws-us-east-1-www-API-80
server SRV_4vhrR 172.31.0.70:80 check weight 128
server SRV_jOEoa 127.0.0.1:80 disabled weight 128
server SRV_tce8j 127.0.0.1:80 disabled weight 128
server SRV_njnGf 127.0.0.1:80 disabled weight 128
server SRV_R0V1R 127.0.0.1:80 disabled weight 128
server SRV_Bc83k 127.0.0.1:80 disabled weight 128
server SRV_mnkyy 127.0.0.1:80 disabled weight 128
server SRV_zMQ6S 127.0.0.1:80 disabled weight 128
server SRV_MowJa 127.0.0.1:80 disabled weight 128
server SRV_4oEP4 127.0.0.1:80 disabled weight 128
frontend public_web_servers
mode http
log global
timeout client
bind *:80
default_backend aws-us-east-1-www-API-80
$ sudo systemctl reload hapee-2.2-lb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment