Skip to content

Commit

Permalink
updating script to check if new cluster exists before triggering the …
Browse files Browse the repository at this point in the history
…create command. Also, increased the sleep time to allow the cluster to come up.
  • Loading branch information
EliseCastle23 committed Oct 17, 2023
1 parent db38652 commit eaa8c69
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions gen3/bin/create-es7-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,42 @@ security_groups=`echo "$cluster_info" | jq -r '.DomainStatus.VPCOptions.Security
access_policies=`echo "$cluster_info" | jq -r '.DomainStatus.AccessPolicies'`
kms_key_id=`echo "$cluster_info" | jq -r '.DomainStatus.EncryptionAtRestOptions.KmsKeyId'`

# Create the new Elasticsearch cluster
aws es create-elasticsearch-domain \
--domain-name "$new_cluster_name" \
--elasticsearch-version "7.10" \
--elasticsearch-cluster-config \
"InstanceType=$instance_type,InstanceCount=$instance_count" \
--ebs-options \
"EBSEnabled=true,VolumeType=$volume_type,VolumeSize=$volume_size" \
--vpc-options "SubnetIds=${subnet_ids[*]},SecurityGroupIds=${security_groups[*]}" \
--access-policies "$access_policies" \
--encryption-at-rest-options "Enabled=true,KmsKeyId=$kms_key_id"\
> /dev/null 2>&1

# Wait for the new cluster to be available
sleep_duration=30
max_retries=10
retry_count=0

while [ $retry_count -lt $max_retries ]; do
cluster_status=$(aws es describe-elasticsearch-domain --domain-name "$new_cluster_name" | jq -r '.DomainStatus.Processing')
if [ "$cluster_status" != "true" ]; then
echo "New cluster is available."
break
fi
sleep $sleep_duration
((retry_count++))
done

if [ $retry_count -eq $max_retries ]; then
echo "New cluster creation may still be in progress. Please check the AWS Management Console for the status."
fi
# Check if the new Elasticsearch cluster name already exists
new_cluster=`aws es describe-elasticsearch-domain --domain-name "$new_cluster_name"`

if [ -n "$new_cluster" ]; then
echo "Cluster $new_cluster_name already exists"
else
echo "Cluster does not exist- creating..."
# Create the new Elasticsearch cluster
aws es create-elasticsearch-domain \
--domain-name "$new_cluster_name" \
--elasticsearch-version "7.10" \
--elasticsearch-cluster-config \
"InstanceType=$instance_type,InstanceCount=$instance_count" \
--ebs-options \
"EBSEnabled=true,VolumeType=$volume_type,VolumeSize=$volume_size" \
--vpc-options "SubnetIds=${subnet_ids[*]},SecurityGroupIds=${security_groups[*]}" \
--access-policies "$access_policies" \
--encryption-at-rest-options "Enabled=true,KmsKeyId=$kms_key_id"\
> /dev/null 2>&1

# Wait for the new cluster to be available
sleep_duration=60
max_retries=10
retry_count=0

while [ $retry_count -lt $max_retries ]; do
cluster_status=$(aws es describe-elasticsearch-domain --domain-name "$new_cluster_name" | jq -r '.DomainStatus.Processing')
if [ "$cluster_status" != "true" ]; then
echo "New cluster is available."
break
fi
sleep $sleep_duration
((retry_count++))
done

if [ $retry_count -eq $max_retries ]; then
echo "New cluster creation may still be in progress. Please check the AWS Management Console for the status."
fi
fi

0 comments on commit eaa8c69

Please sign in to comment.