Add filtering over ec2 metadata to cover cases when there are a lot of instances

This commit is contained in:
Greg Fodor 2019-08-27 21:53:03 +00:00
Родитель 2dba6f803a
Коммит fe83123356
3 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -15,7 +15,7 @@ ENV=""
# There is a race condition on EC2 metadata, it can be not ready yet or have no tags yet.
while [[ -z "$EC2_INFO" || -z "$HAB_RING" || -z "$ENV" ]] ; do
EC2_INFO=$(aws ec2 --region us-west-1 describe-instances)
EC2_INFO=$(aws ec2 --region us-west-1 describe-instances --instance-ids $INSTANCE_ID)
# Get the ring name
HAB_RING=$(echo "$EC2_INFO" | jq -r ".Reservations | map(.Instances) | flatten | .[] | select(.InstanceId == \"$INSTANCE_ID\") | .Tags | .[]? | select(.Key == \"hab-ring\") | .Value ")

Просмотреть файл

@ -9,7 +9,7 @@ if [[ ! -f ~/.aws_region ]] ; then
fi
if [[ ! -f ~/.aws_host_type ]] ; then
aws ec2 --region $(cat ~/.aws_region) describe-instances | jq -r ".Reservations | map(.Instances) | flatten | .[] | select(.InstanceId == \"$(cat ~/.aws_instance_id)\") | .Tags | .[] | select(.Key == \"host-type\") | .Value " > ~/.aws_host_type
aws ec2 --region $(cat ~/.aws_region) describe-instances --instance-ids $(cat ~/.aws_instance_id) | jq -r ".Reservations | map(.Instances) | flatten | .[] | select(.InstanceId == \"$(cat ~/.aws_instance_id)\") | .Tags | .[] | select(.Key == \"host-type\") | .Value " > ~/.aws_host_type
fi
export PS1="\[\033[01;34m\]$(cat ~/.aws_host_type) $PS1"

Просмотреть файл

@ -24,7 +24,7 @@ attempt_generate_hostname() {
DNS_IP=$(dig $NEW_HOSTNAME.$HOSTED_ZONE_NAME A +short)
if [[ ! -z "$DNS_IP" ]] ; then
EXISTING_IP=$(aws ec2 --region $REGION describe-instances | grep $DNS_IP)
EXISTING_IP=$(aws ec2 --region $REGION describe-instances --no-paginate | grep $DNS_IP)
fi
}