Skip to content

Commit 216fbb1

Browse files
committed
Merge pull request #4535 from helgi/aws-query
ref(aws): Improve AWS queries instead of piping output.
2 parents d6be99a + f4b4056 commit 216fbb1

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
@@ -122,28 +122,27 @@ aws ec2 describe-instances \
122122
$EXTRA_AWS_CLI_ARGS
123123
124124
# get ELB public DNS name through cloudformation
125-
# TODO: is "first output value" going to be reliable enough?
126125
export ELB_DNS_NAME=$(aws cloudformation describe-stacks \
127126
--stack-name $STACK_NAME \
128127
--max-items 1 \
129-
--query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \
128+
--query 'Stacks[].[ Outputs[?OutputKey==`DNSName`].OutputValue ] ]' \
130129
--output=text \
131130
$EXTRA_AWS_CLI_ARGS)
132131
133132
# get ELB friendly name through aws elb
134133
ELB_NAME=$(aws elb describe-load-balancers \
135-
--query 'LoadBalancerDescriptions[].[ DNSName,LoadBalancerName ]' \
134+
--query "LoadBalancerDescriptions[?DNSName=='$ELB_DNS_NAME'].[ LoadBalancerName ]" \
136135
--output=text \
137-
$EXTRA_AWS_CLI_ARGS | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
136+
$EXTRA_AWS_CLI_ARGS)
138137
echo "Using ELB $ELB_NAME at $ELB_DNS_NAME"
139138
140139
# Instance launched into a VPC may not have a PublicIPAddress
141140
for ip_type in PublicIpAddress PrivateIpAddress; do
142141
FIRST_INSTANCE=$(aws ec2 describe-instances \
143142
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
144-
--query "Reservations[].Instances[].[$ip_type]" \
143+
--query "Reservations[].Instances[].[$ip_type][0]" \
145144
--output text \
146-
$EXTRA_AWS_CLI_ARGS | head -1)
145+
$EXTRA_AWS_CLI_ARGS)
147146
if [[ ! $FIRST_INSTANCE == "None" ]]; then
148147
break
149148
fi

0 commit comments

Comments
 (0)