> ## 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.

# Elasticsearch Reserved Instance Should Not Have Status - Payment Pending

### More Info:

Identify any pending Amazon Elasticsearch (ES) Reserved Instances available in your AWS account and solve these incomplete ES reservations by requesting AWS Support to retry the necessary payments

### Risk Level

Low

### Address

Cost Optimisation

### Compliance Standards

CBP

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        Sure, here are the step-by-step instructions to remediate the Elasticsearch Reserved Instance Payment Pending misconfiguration in AWS:

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

        2. Click on the "Reserved instances" tab in the left-hand menu.

        3. Locate the Elasticsearch Reserved Instance with the "Payment Pending" status.

        4. Click on the "Actions" button for that instance.

        5. Select "Modify Reserved Instance" from the dropdown menu.

        6. In the "Modify Reserved Instance" dialog box, select the "Apply RI upfront" option.

        7. Choose the payment option that you prefer, either "All Upfront" or "Partial Upfront".

        8. Review the details of the reservation and click "Purchase".

        9. Wait for the payment to be processed. Once the payment is processed, the instance status will change from "Payment Pending" to "Active".

        That's it! You have successfully remediated the Elasticsearch Reserved Instance Payment Pending misconfiguration in AWS.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the Elasticsearch Reserved Instance with a payment pending status in AWS using AWS CLI, follow these steps:

        1. Open the AWS CLI on your local machine.

        2. Check the status of your Elasticsearch Reserved Instance by running the following command:

           ```
           aws es describe-reserved-elasticsearch-instances
           ```

        3. Identify the Elasticsearch Reserved Instance with a payment pending status.

        4. Modify the Elasticsearch Reserved Instance by running the following command:

           ```
           aws es modify-reserved-elasticsearch-instances --reserved-elasticsearch-instance-id <your-reserved-instance-id> --payment-option AllUpfront
           ```

           Note: Replace `<your-reserved-instance-id>` with the ID of the Elasticsearch Reserved Instance that has a payment pending status.

        5. Verify that the Elasticsearch Reserved Instance status has changed to active by running the following command:

           ```
           aws es describe-reserved-elasticsearch-instances
           ```

        6. If the Elasticsearch Reserved Instance status has not changed to active, contact AWS Support for further assistance.

        By following these steps, you can remediate the Elasticsearch Reserved Instance with a payment pending status in AWS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the Elasticsearch Reserved Instance with status "Payment Pending" in AWS using Python, follow these steps:

        1. Import the necessary AWS SDKs and libraries in your Python script, such as `boto3` and `botocore`.

        2. Create an AWS client for Elasticsearch using the `boto3.client()` method.

        ```python theme={null}
        import boto3

        es = boto3.client('es')
        ```

        3. Use the `describe_reserved_elasticsearch_instances()` method to get the details of all the reserved Elasticsearch instances in your AWS account.

        ```python theme={null}
        reserved_instances = es.describe_reserved_elasticsearch_instances()
        ```

        4. Loop through the reserved instances and check for the ones with the status "Payment Pending".

        ```python theme={null}
        for instance in reserved_instances['ReservedElasticsearchInstances']:
            if instance['State'] == 'payment-pending':
                # remediation steps go here
        ```

        5. To remediate the instance, you can modify the payment option for the reserved instance using the `modify_reserved_elasticsearch_instance()` method.

        ```python theme={null}
        es.modify_reserved_elasticsearch_instance(
            ReservedElasticsearchInstanceId='instance-id',
            PaymentOption='AllUpfront'
        )
        ```

        6. Once the payment option is modified, check the status of the reserved instance again using the `describe_reserved_elasticsearch_instances()` method to ensure that the status has been updated.

        ```python theme={null}
        reserved_instances = es.describe_reserved_elasticsearch_instances()

        for instance in reserved_instances['ReservedElasticsearchInstances']:
            if instance['ReservedElasticsearchInstanceId'] == 'instance-id':
                if instance['State'] != 'payment-pending':
                    print('Reserved instance status updated successfully')
        ```

        7. Finally, test the remediation by verifying the status of the reserved instance in the AWS Management Console or by using the `describe_reserved_elasticsearch_instances()` method again.

        Note: Make sure that you have the necessary permissions to modify reserved Elasticsearch instances in your AWS account.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-ri.html](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-ri.html)
