This Docker container allows you to (de)register an EC2 instance with an Amazon Elastic Load Balancer Target Group.
(Inspired by: https://github.com/coreos/elb-presence)
The elbtg-presence
container takes all of its configuration from environment
variables.
docker run --rm --name example-presence -e AWS_ACCESS_KEY=<key> -e AWS_SECRET_KEY=<secret> -e AWS_REGION=us-east-1 -e AWS_TARGET_GROUP=ExampleTargetGroup quay.io/sfurnival/elbtg-presence
AWS_ACCESS_KEY
... Your AWS access keyAWS_SECRET_KEY
... Your AWS secret keyAWS_REGION
... The AWS region that your load balancer is located inAWS_TARGET_GROUP
... The ARN for the desired Target Group
Usually you'll want to manage the lifecycle of your presence service using fleet. To do so, you can create a service file similar to this example:
[Unit]
Description=Example Presence Service
BindsTo=my-service@%i.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/usr/bin/docker pull quay.io/sfurnival/elbtg-presence:latest
ExecStart=/usr/bin/docker run --rm --name %p-%i -e AWS_ACCESS_KEY=<key> -e AWS_SECRET_KEY=<secret> -e AWS_REGION=us-east-1 -e AWS_TARGET_GROUP=ExampleTargetGroup quay.io/sfurnival/elbtg-presence
ExecStop=/usr/bin/docker stop %p-%i
[X-Fleet]
MachineOf=my-service@%i.service
This service will deploy to the same machine as your service (MachineOf
) and
automatically start and stop along with it (BindsTo
).