Last active
January 31, 2018 16:50
-
-
Save Jinkxed/99ba78a7cb1e7b5573ea131cf2015cad to your computer and use it in GitHub Desktop.
get-meta.sh
This file contains 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 | |
. /etc/bashrc | |
# EC2 Metadata | |
export REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document/ | jq .region -r) | |
export INSTANCEID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
# Get all tags in one call | |
ec2-describe-tags --filter "resource-type=instance" --filter "resource-id=$(ec2-metadata -i | cut -d ' ' -f2)" | cut -f 4,5 > /tmp/ec2_tags | |
result=$? | |
while [[ $result != 0 ]]; do | |
echo "- Requestlimit Exceeded Retrying." | |
sleep 5 | |
ec2-describe-tags --filter "resource-type=instance" --filter "resource-id=$(ec2-metadata -i | cut -d ' ' -f2)" | cut -f 4,5 > /tmp/ec2_tags | |
result=$? | |
done | |
export NAME=$(cat /tmp/ec2_tags | grep -w "Name" | cut -f2) | |
export ENVIRONMENT=$(cat /tmp/ec2_tags | grep Environment | cut -f2) | |
export ROLE=$(cat /tmp/ec2_tags | grep Role | cut -f2) | |
export TEAM=$(cat /tmp/ec2_tags | grep Team | cut -f2) | |
export PRODUCT=$(cat /tmp/ec2_tags | grep Product | cut -f2) | |
export AS_GROUPNAME=$(cat /tmp/ec2_tags | grep groupName | cut -f2) | |
export AS_STACKNAME=$(cat /tmp/ec2_tags | grep stack-name | cut -f2) | |
export RAILS_ENV=$ENVIRONMENT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment