> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Es instance counts remediation

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        The ElasticSearch instance count misconfiguration can cause issues with performance and availability. Here are the steps to remediate this issue in AWS using the AWS console:

        1. Open the AWS Management Console and navigate to the ElasticSearch service.

        2. Select the ElasticSearch domain for which you want to modify the instance count.

        3. In the domain dashboard, click on the "Modify Cluster" button.

        4. In the "Modify Cluster" page, scroll down to the "Instance Count" section.

        5. Update the instance count to the desired number. It is recommended to have at least three instances for high availability.

        6. Click on the "Review and Submit" button to review your changes.

        7. Review the changes and click on the "Modify Cluster" button to apply the changes.

        8. Wait for the changes to be applied. This may take several minutes.

        9. Once the changes are applied, verify that the ElasticSearch cluster is running smoothly.

        By following these steps, you can remediate the ElasticSearch instance count misconfiguration in AWS using the AWS console.

        #
      </Accordion>

      <Accordion title="Using CLI">
        The Elasticsearch Instance Count misconfiguration in AWS means that there are either too many or too few Elasticsearch instances running. To remediate this issue using AWS CLI, follow these steps:

        1. Open the AWS CLI and connect to your AWS account.

        2. Run the following command to describe the current Elasticsearch domain:

        ```
        aws es describe-elasticsearch-domain --domain-name <your-domain-name>
        ```

        3. Check the value of the `ElasticsearchClusterConfig.InstanceCount` parameter. This parameter specifies the number of instances in the Elasticsearch cluster.

        4. If the value of the `ElasticsearchClusterConfig.InstanceCount` parameter is too high or too low, you can update it using the following command:

        ```
        aws es update-elasticsearch-domain-config --domain-name <your-domain-name> --elasticsearch-cluster-config InstanceCount=<new-instance-count>
        ```

        Replace `<your-domain-name>` with the name of your Elasticsearch domain, and `<new-instance-count>` with the desired number of instances.

        5. After running the `update-elasticsearch-domain-config` command, wait for a few minutes for the changes to take effect.

        6. Run the `describe-elasticsearch-domain` command again to verify that the `ElasticsearchClusterConfig.InstanceCount` parameter has been updated.

        7. Finally, test the Elasticsearch cluster to ensure that it is functioning correctly with the new instance count.

        By following these steps, you can remediate the Elasticsearch Instance Count misconfiguration in AWS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        The misconfiguration of Elasticsearch Instance Count in AWS can be remediated using the following steps:

        1. Open the AWS Management Console and navigate to the Elasticsearch service.
        2. Click on the Elasticsearch domain that you want to remediate.
        3. Click on the "Edit" button in the "Instance Settings" section.
        4. In the "Instance Count" field, enter the desired number of instances for your Elasticsearch domain.
        5. Click on the "Save Changes" button to apply the new instance count.

        To automate this process using Python, you can use the AWS SDK for Python (Boto3) to update the instance count programmatically. Here's an example code snippet:

        ```python theme={null}
        import boto3

        # Replace <your-domain-name> with the name of your Elasticsearch domain
        domain_name = '<your-domain-name>'
        new_instance_count = 2

        # Create an Elasticsearch client using Boto3
        es_client = boto3.client('es')

        # Update the instance count for the specified domain
        response = es_client.update_elasticsearch_domain_config(
            DomainName=domain_name,
            ElasticsearchClusterConfig={
                'InstanceCount': new_instance_count
            }
        )

        # Print the response from the API
        print(response)
        ```

        This code will update the instance count for your Elasticsearch domain to the specified value. You can run this code as a script or integrate it into your existing Python application.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "aws_elasticsearch_domain" "THIS_DOMAIN" {
          # Replace THIS_DOMAIN with the Terraform name for the Elasticsearch domain
          domain_name = "ELASTICSEARCH_DOMAIN_NAME" # replace with the actual domain name

          cluster_config {
            instance_type  = "ELASTICSEARCH_INSTANCE_TYPE"  # e.g. "m5.large.elasticsearch"
            instance_count = DESIRED_INSTANCE_COUNT_BELOW_THRESHOLD
            # set this to the lower number of instances your organization’s quota/threshold allows
          }

          # ... keep any other required arguments for your domain here (ebs_options, access_policies, etc.)
        }
        ```

        To *delete* an unnecessary Elasticsearch domain (equivalent to `aws es delete-elasticsearch-domain`), remove the corresponding `aws_elasticsearch_domain` resource block from your Terraform configuration and run `terraform apply`; this will permanently delete the domain and all of its data, and this action is irreversible, so back up any required data and ensure the domain is no longer needed before applying.

        Changing only `cluster_config.instance_count` to a lower value is an in-place update and does not force resource replacement; `terraform plan` should show either:

        * a `-/+` destroy-and-create change for the domain if you removed the resource block (full deletion), or
        * an `~` update with `instance_count` changing from the current value to `DESIRED_INSTANCE_COUNT_BELOW_THRESHOLD` if you are just resizing the cluster.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
