Skip to content

Instantly share code, notes, and snippets.

@aarondodd
Created March 13, 2018 14:56
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 aarondodd/76968a1a745717669bf88269191711fd to your computer and use it in GitHub Desktop.
Save aarondodd/76968a1a745717669bf88269191711fd to your computer and use it in GitHub Desktop.
scale an aurora cluster writer node
#!/bin/bash
instance_size=$1
cluster_id="mycoolcluster-xxxx"
primary_node="mycoolcluster-node"
region="us-east-1"
pending_status=""
check_for='"PendingModifiedValues": {},'
aws rds modify-db-instance --db-instance-identifier "${primary_node}" --db-instance-class "${instance_size}" --apply-immediately --region "${region}"
echo "Checking status for ${primary_node}..."
until [ "${pending_status}" != "" ]; do
pending_status=$(aws rds describe-db-instances --db-instance-identifier "${primary_node}" --region "${region}" --output json | grep "${check_for}")
echo "${primary_node} still pending changes, waiting."
sleep 10
done
echo "Failing back to ${primary_node}"
# sometimes it seems pending status is removed but node is not yet ready for failback (likely pending-reboot but not shown in CLI response)
# so if an error occurs, keep trying (there's probably a better way to do this)
while [ $? -ne 0 ]; do
aws rds failover-db-cluster --db-cluster-identifier "${cluster_id}" --target-db-instance-identifier "${primary_node}" --region "${region}"
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment