Created
February 12, 2019 16:47
-
-
Save dsmrt/dda459aef5ccbe2c7eae359c9e3e9b47 to your computer and use it in GitHub Desktop.
AWS ElasticBeanstalk helper - Only run command on one server in an EB environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo "Usage run-on-one-server.bash <eb-environment-name>"; | |
exit 0; | |
fi | |
LEADER_INSTANCE=$(aws --region us-west-2 ec2 describe-instances --filters "Name=instance-state-name,Values=running" "Name=tag:elasticbeanstalk:environment-name,Values=$1" | jq '[.Reservations[].Instances[0]] | sort_by(.LaunchTime) | .[0].InstanceId' -r) | |
THIS_INSTANCE=$(curl http://169.254.169.254/latest/meta-data/instance-id) | |
if [ "$LEADER_INSTANCE" == "$THIS_INSTANCE" ]; then | |
#return success | |
exit 0; | |
fi | |
#return error | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment