Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/bin/redshift/setup-aws-redshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ echo "Waiting for the Amazon Redshift cluster ${REDSHIFT_CLUSTER_IDENTIFIER} on
aws redshift wait cluster-available \
--cluster-identifier ${REDSHIFT_CLUSTER_IDENTIFIER}

echo "The Amazon Redshift cluster ${REDSHIFT_CLUSTER_IDENTIFIER} on the region ${AWS_REGION} is available for queries."
echo "The Amazon Redshift cluster ${REDSHIFT_CLUSTER_IDENTIFIER} on the region ${AWS_REGION} reports available status."

REDSHIFT_CLUSTER_DESCRIPTION=$(aws redshift describe-clusters --cluster-identifier ${REDSHIFT_CLUSTER_IDENTIFIER})

Expand All @@ -52,3 +52,21 @@ export REDSHIFT_PORT=$(echo ${REDSHIFT_CLUSTER_DESCRIPTION} | jq -r '.Clusters[0
export REDSHIFT_CLUSTER_DATABASE_NAME=$(echo ${REDSHIFT_CLUSTER_DESCRIPTION} | jq -r '.Clusters[0].DBName' )
export REDSHIFT_USER=$(echo ${REDSHIFT_CLUSTER_DESCRIPTION} | jq -r '.Clusters[0].MasterUsername' )
export REDSHIFT_PASSWORD

# The AWS API status "available" doesn't guarantee the endpoint is accepting connections yet.
# Poll the actual TCP port until Redshift is truly ready.
echo "Waiting for the Redshift endpoint ${REDSHIFT_ENDPOINT}:${REDSHIFT_PORT} to accept connections..."
MAX_RETRIES=30
RETRY_INTERVAL_SECONDS=10
for ((i=1; i<=MAX_RETRIES; i++)); do
if nc -z -w 5 "${REDSHIFT_ENDPOINT}" "${REDSHIFT_PORT}" 2>/dev/null; then
echo "The Amazon Redshift cluster ${REDSHIFT_CLUSTER_IDENTIFIER} on the region ${AWS_REGION} is accepting connections."
break
fi
if [ "$i" -eq "$MAX_RETRIES" ]; then
echo "ERROR: Redshift endpoint ${REDSHIFT_ENDPOINT}:${REDSHIFT_PORT} did not become reachable after $((MAX_RETRIES * RETRY_INTERVAL_SECONDS)) seconds."
exit 1
fi
echo " Attempt ${i}/${MAX_RETRIES}: endpoint not ready yet, retrying in ${RETRY_INTERVAL_SECONDS}s..."
sleep ${RETRY_INTERVAL_SECONDS}
done