From eaa8c69733a96491dc3abdc611a74d96f1968a6c Mon Sep 17 00:00:00 2001 From: EliseCastle23 Date: Tue, 17 Oct 2023 12:51:52 -0600 Subject: [PATCH] updating script to check if new cluster exists before triggering the create command. Also, increased the sleep time to allow the cluster to come up. --- gen3/bin/create-es7-cluster.sh | 70 +++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/gen3/bin/create-es7-cluster.sh b/gen3/bin/create-es7-cluster.sh index dec51aeae..d18c4203f 100644 --- a/gen3/bin/create-es7-cluster.sh +++ b/gen3/bin/create-es7-cluster.sh @@ -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 \ No newline at end of file