Skip to content

Commit b9273e7

Browse files
committed
cache result of describe-auto-scaling-instances
1 parent a25ccfc commit b9273e7

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

config/plugin/launch_config_drift.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ if [ -z "${instance_id}" ]; then
2222
exit $UNKNOWN
2323
fi
2424

25-
instances="$(aws autoscaling describe-auto-scaling-instances --instance-ids "${instance_id}" 2>/dev/null)"
25+
INSTANCE_CACHE="/tmp/npd_asg_instance_cache"
2626

27-
if [ -z "${instances}" ] || ! echo "${instances}" | jq empty 2>/dev/null; then
28-
exit $UNKNOWN
27+
if [ -f "$INSTANCE_CACHE" ]; then
28+
instances="$(cat "$INSTANCE_CACHE")"
29+
else
30+
instances="$(aws autoscaling describe-auto-scaling-instances --instance-ids "${instance_id}" 2>&1)"
31+
if [ $? -ne 0 ]; then
32+
echo "describe-auto-scaling-instances: ${instances}" >&2
33+
exit $UNKNOWN
34+
fi
35+
echo "${instances}" > "$INSTANCE_CACHE"
2936
fi
3037

3138
if [ "$(echo "${instances}" | jq '.AutoScalingInstances | length')" -eq "0" ]; then
@@ -38,9 +45,9 @@ instance_launch_template_version="$(echo "${instance}" | jq -r .LaunchTemplate.V
3845
instance_asg="$(echo "${instance}" | jq -r .AutoScalingGroupName)"
3946

4047
# Get ASG's current launch template (still requires AWS API)
41-
asgs="$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names "${instance_asg}" 2>/dev/null)"
42-
43-
if [ -z "${asgs}" ] || ! echo "${asgs}" | jq empty 2>/dev/null; then
48+
asgs="$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names "${instance_asg}" 2>&1)"
49+
if [ $? -ne 0 ]; then
50+
echo "describe-auto-scaling-groups: ${asgs}" >&2
4451
exit $UNKNOWN
4552
fi
4653

0 commit comments

Comments
 (0)