Skip to content

Commit f4b4056

Browse files
committed
ref(aws): Improve AWS queries instead of piping output.
Fully utilise the power of aws cli query instead of piping various AWS commands into cut, head and other programs
1 parent 46a5ec7 commit f4b4056

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

contrib/aws/check

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ function check-elb-service {
1515
rigger-log "Waiting for ELB (${elb_name}) to see an instance in InService..."
1616
IN_SERVICE=$(aws elb describe-instance-health \
1717
--load-balancer-name "${elb_name}" \
18-
--query 'InstanceStates[].State' \
19-
| grep InService \
20-
| wc -l)
18+
--query 'length(InstanceStates[?State==`InService`])')
2119
done
2220
}
2321

contrib/aws/provision-aws-cluster.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,27 @@ aws ec2 describe-instances \
121121
$EXTRA_AWS_CLI_ARGS
122122
123123
# get ELB public DNS name through cloudformation
124-
# TODO: is "first output value" going to be reliable enough?
125124
export ELB_DNS_NAME=$(aws cloudformation describe-stacks \
126125
--stack-name $STACK_NAME \
127126
--max-items 1 \
128-
--query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \
127+
--query 'Stacks[].[ Outputs[?OutputKey==`DNSName`].OutputValue ] ]' \
129128
--output=text \
130129
$EXTRA_AWS_CLI_ARGS)
131130
132131
# get ELB friendly name through aws elb
133132
ELB_NAME=$(aws elb describe-load-balancers \
134-
--query 'LoadBalancerDescriptions[].[ DNSName,LoadBalancerName ]' \
133+
--query "LoadBalancerDescriptions[?DNSName=='$ELB_DNS_NAME'].[ LoadBalancerName ]" \
135134
--output=text \
136-
$EXTRA_AWS_CLI_ARGS | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
135+
$EXTRA_AWS_CLI_ARGS)
137136
echo "Using ELB $ELB_NAME at $ELB_DNS_NAME"
138137
139138
# Instance launched into a VPC may not have a PublicIPAddress
140139
for ip_type in PublicIpAddress PrivateIpAddress; do
141140
FIRST_INSTANCE=$(aws ec2 describe-instances \
142141
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
143-
--query "Reservations[].Instances[].[$ip_type]" \
142+
--query "Reservations[].Instances[].[$ip_type][0]" \
144143
--output text \
145-
$EXTRA_AWS_CLI_ARGS | head -1)
144+
$EXTRA_AWS_CLI_ARGS)
146145
if [[ ! $FIRST_INSTANCE == "None" ]]; then
147146
break
148147
fi

0 commit comments

Comments
 (0)