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

### More Info:

Your AWS Account should not have any failed Amazon Elasticsearch (ES) Reserved Instances.

### Risk Level

Low

### Address

Cost Optimisation

### Compliance Standards

CBP

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the Elasticsearch Reserved Instance Payment Failed status in AWS, you can follow these steps:

        1. Log in to your AWS Console and navigate to the Elasticsearch service.

        2. Click on the "Reserved Instances" tab on the left-hand side of the screen.

        3. Identify the Reserved Instance that has the Payment Failed status.

        4. Click on the Reserved Instance ID to view the details.

        5. On the "Details" tab, scroll down to the "Payment Information" section.

        6. Click on the "Modify Payment Method" button.

        7. Update the payment method with valid payment information.

        8. Click on the "Save Changes" button.

        9. Wait for a few minutes for the payment status to update.

        10. Refresh the page to confirm that the status has been updated to "Active".

        Once the status has been updated to "Active", the Elasticsearch Reserved Instance will be available for use.

        #
      </Accordion>

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

        1. Open the AWS CLI on your local machine.

        2. Run the following command to get the ID of the Elasticsearch Reserved Instance:

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

        3. Identify the ID of the Elasticsearch Reserved Instance with the status "Payment Failed".

        4. Run the following command to modify the Elasticsearch Reserved Instance:

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

        Replace `<ID>` with the ID of the Elasticsearch Reserved Instance identified in step 3.

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

        ```
        aws es describe-reserved-elasticsearch-instances --reserved-elasticsearch-instance-id <ID>
        ```

        The Elasticsearch Reserved Instance should now be remediated and have a status of "Active".
      </Accordion>

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

        1. Import the necessary AWS SDK libraries for Python. You can use the `boto3` library for this.

        ```python theme={null}
        import boto3
        ```

        2. Create an instance of the `boto3` client for Elasticsearch.

        ```python theme={null}
        es_client = boto3.client('es')
        ```

        3. Use the `describe_reserved_elasticsearch_instance_offerings` method of the Elasticsearch client to get a list of available Elasticsearch reserved instance offerings.

        ```python theme={null}
        reserved_instance_offerings = es_client.describe_reserved_elasticsearch_instance_offerings()
        ```

        4. Loop through the reserved instance offerings and check if there are any with a `PaymentFailure` status.

        ```python theme={null}
        for offering in reserved_instance_offerings['ReservedElasticsearchInstanceOfferings']:
            if offering['PaymentOption'] == 'Reserved' and offering['PaymentPlan'] == 'AllUpfront' and offering['State'] == 'payment-failed':
                # do something to remediate the payment failure
        ```

        5. To remediate the payment failure, you can use the `purchase_reserved_elasticsearch_instance_offering` method of the Elasticsearch client to purchase a new reserved instance offering with the same specifications as the failed one. You can then cancel the failed reserved instance offering using the `cancel_reserved_elasticsearch_instance` method.

        ```python theme={null}
        # purchase a new reserved instance offering
        new_offering = es_client.purchase_reserved_elasticsearch_instance_offering(
            ReservedElasticsearchInstanceOfferingId=offering['ReservedElasticsearchInstanceOfferingId'],
            InstanceCount=offering['InstanceCount']
        )

        # cancel the failed reserved instance offering
        es_client.cancel_reserved_elasticsearch_instance(
            ReservedElasticsearchInstanceId=offering['ReservedElasticsearchInstanceId']
        )
        ```

        6. You can also set up a CloudWatch event to monitor for Elasticsearch reserved instance payment failures and trigger a Lambda function to automatically remediate them.
      </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)
