#!/bin/bash help () { printf "10-disable-logical-replication.sh\n" printf "Usage: 10-disable-logical-replication.sh [ -s ] [ -r ] [ -h ] \n" printf " -- \nWhere: \n" printf " -s The inital AWS Stack name which is to create the vpc, subnet, and Aurora cluster. \n" printf " Whatever value is set when running script 01-install_prereq.sh is what should be retained\n" printf " for the rest of the demo scripts. This flag can be avoided if AURORA_DB_CFSTACK_NAME is \n" printf " set as an environment variable. \n" printf " -r The AWS Region we're running this demo in. This setting needs to stay the same across all scripts run.\n" printf " Using this flag can be avoided if AWS_DEFAULT_REGION is set as an environment variable where running this script\n" printf " -h show help page.\n" } while getopts 's:r:h' flag; do case "${flag}" in s) AURORA_DB_CFSTACK_NAME="${OPTARG}" ;; r) AWS_DEFAULT_REGION="${OPTARG}" ;; h) show_help='true' ;; *) error "Unexpected option ${flag}" ;; esac done if [[ $show_help == "true" ]] then help exit 0 fi # Check that region var is set if [ -z $AURORA_DB_CFSTACK_NAME ] then printf "The AWS stack var isn't set. Please use -s to set this stack, and ensure it's already completed sucessfully.\n" help exit 1 else printf "The AWS Stack is set, continuing.\n" fi # Check that region var is set if [ -z $AWS_DEFAULT_REGION ] then printf "The AWS default region var isn't set. Please use -r to set this stack.\n" help exit 1 else printf "The AWS default region is set, continuing.\n" fi ## Mainline echo "Disabling logical replication for your PostgeSQL Database" echo "DB stack name is:" $AURORA_DB_CFSTACK_NAME ClusterName=$(aws cloudformation describe-stacks --stack-name $AURORA_DB_CFSTACK_NAME | jq -r '.Stacks[].Outputs[] | select(.OutputKey=="ClusterName") | .OutputValue') CLUSTER_PARAM_GROUP=$(aws rds describe-db-clusters --db-cluster-identifier $ClusterName | jq -r '.DBClusters[].DBClusterParameterGroup') DB_INSTANCE_IDENTIFIER=$(aws rds describe-db-clusters --db-cluster-identifier $ClusterName | jq -r '.DBClusters[].DBClusterMembers[].DBInstanceIdentifier') aws rds modify-db-cluster-parameter-group --db-cluster-parameter-group-name $CLUSTER_PARAM_GROUP --parameters "ParameterName=rds.logical_replication,ParameterValue=0,ApplyMethod=pending-reboot" aws rds reboot-db-instance --db-instance-identifier $DB_INSTANCE_IDENTIFIER