Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristim/82fc6bfe56c67a22ee264a0e3b655df5 to your computer and use it in GitHub Desktop.
Save cristim/82fc6bfe56c67a22ee264a0e3b655df5 to your computer and use it in GitHub Desktop.
get-meta.sh
#!/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