> ## 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 ri lease expiration 7 days remediation

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the Elasticsearch Reserved Instance Lease Expiration in the next 7 Days issue in AWS, follow these steps:

        1. Log in to the AWS Management Console.

        2. Go to the Elasticsearch service.

        3. Click on the "Reserved Instances" tab.

        4. Look for the instance that has an expiration date in the next 7 days.

        5. Click on the "Modify Reserved Instances" button.

        6. Select the "Extend the reservation" option.

        7. Choose the number of months to extend the reservation for.

        8. Click on the "Purchase" button.

        9. Review the details of the reservation extension and confirm the purchase.

        10. Once the purchase is complete, the Elasticsearch Reserved Instance will be renewed and the expiration date will be extended.

        11. Repeat the steps for any other Elasticsearch Reserved Instances that have an expiration date in the next 7 days.

        By following these steps, you will be able to remediate the Elasticsearch Reserved Instance Lease Expiration in the next 7 Days issue in AWS.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the Elasticsearch Reserved Instance Lease Expiration in the next 7 days in AWS, follow these steps:

        1. Open the AWS CLI on your local machine.

        2. Check the Elasticsearch Reserved Instance Lease Expiration status by running the following command:

           ```
           aws es describe-reserved-elasticsearch-instance-offerings --query 'ReservedElasticsearchInstanceOfferings[?Duration == `31536000` && FixedPrice == `0.0` && State == `ACTIVE` && UsagePrice == `0.0` && PaymentOption == `AllUpfront` && OfferingType == `HeavyUtilization` && DurationUnits == `Seconds` && ElasticsearchInstanceType == `m4.large.elasticsearch` && ReservedElasticsearchInstanceOfferingId != `null` && Start == `null` && End != `null` && End < `'"$(date -v+7d +%Y-%m-%dT%H:%M:%SZ)"'`]' --output table
           ```

           This command will list all Elasticsearch Reserved Instances with lease expiration in the next 7 days.

        3. To remediate this issue, you need to renew the lease of the Elasticsearch Reserved Instances. To do this, run the following command:

           ```
           aws es purchase-reserved-elasticsearch-instances-offering --reserved-elasticsearch-instance-offering-id <RESERVED_INSTANCE_ID> --instance-count <INSTANCE_COUNT> --payment-option AllUpfront
           ```

           Replace `<RESERVED_INSTANCE_ID>` with the ID of the Elasticsearch Reserved Instance that you want to renew, and `<INSTANCE_COUNT>` with the number of instances you want to reserve. This command will renew the lease of the Elasticsearch Reserved Instance for another year.

        4. Verify that the Elasticsearch Reserved Instance Lease Expiration status is updated by running the command in step 2 again.

        5. Repeat steps 3-4 for any other Elasticsearch Reserved Instances that have lease expiration in the next 7 days.

        By following these steps, you can remediate the Elasticsearch Reserved Instance Lease Expiration issue in AWS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the Elasticsearch Reserved Instance Lease Expiration issue in AWS using Python, you can follow the below steps:

        1. Import the required AWS SDK libraries - Boto3 and Datetime.

        ```python theme={null}
        import boto3
        from datetime import datetime, timedelta
        ```

        2. Create a Boto3 client for Elasticsearch.

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

        3. Get the list of Elasticsearch reserved instances.

        ```python theme={null}
        reserved_instances = es_client.describe_reserved_elasticsearch_instances()['ReservedElasticsearchInstances']
        ```

        4. Iterate through the reserved instances and check if any of them are expiring in the next 7 days.

        ```python theme={null}
        for instance in reserved_instances:
            expiration_date = instance['EndTime']
            days_left = (expiration_date - datetime.now()).days
            if days_left <= 7:
                # Remediation steps go here.
        ```

        5. If a reserved instance is expiring in the next 7 days, you can take remediation steps such as renewing the reservation or purchasing a new one. For example, to renew the reservation, you can use the `purchase_reserved_elasticsearch_instance_offering` method.

        ```python theme={null}
        es_client.purchase_reserved_elasticsearch_instance_offering(
            ReservedElasticsearchInstanceOfferingId='string',
            ReservationName='string',
            InstanceCount=123
        )
        ```

        6. Once the remediation steps are completed, you can update your ticketing system or log the remediation in a file.

        ```python theme={null}
        # Update ticketing system or log the remediation.
        ```

        By following these steps, you can remediate the Elasticsearch Reserved Instance Lease Expiration issue in AWS using Python.
      </Accordion>

      <Accordion title="Using Terraform">
        Terraform cannot renew or purchase Amazon Elasticsearch/OpenSearch Reserved Instances; the AWS APIs for `purchase-reserved-elasticsearch-instance-offering` are not exposed via the `hashicorp/aws` provider, so there is no valid Terraform resource or argument for this operation.

        You must perform this as a runtime/financial action via AWS CLI or console, following the exact steps in the verified remediation:

        ```bash theme={null}
        # 1. Inspect the expiring RI
        aws es describe-reserved-elasticsearch-instances \
          --reserved-elasticsearch-instance-id EXISTING_RESERVED_INSTANCE_ID \
          --region AWS_REGION

        # 2. List available offerings and select one that matches your needs
        aws es describe-reserved-elasticsearch-instance-offerings \
          --region AWS_REGION

        # 3. Purchase (renew) a new Reserved Instance
        aws es purchase-reserved-elasticsearch-instance-offering \
          --region AWS_REGION \
          --reserved-elasticsearch-instance-offering-id SELECTED_OFFERING_ID \
          --reservation-name NEW_RESERVATION_NAME \
          --instance-count EXISTING_INSTANCE_COUNT
        ```

        Replace:

        * `EXISTING_RESERVED_INSTANCE_ID` with the ID of the expiring RI.
        * `AWS_REGION` with the RI’s region.
        * `SELECTED_OFFERING_ID` with an offering from step 2 that matches your instance type/term/payment option.
        * `NEW_RESERVATION_NAME` with your desired name.
        * `EXISTING_INSTANCE_COUNT` with the current RI’s instance count.

        Because Terraform cannot model or manage these RI purchases, `terraform plan` and `terraform apply` will show **no changes** related to Reserved Instances; verification must be done via the AWS console or `aws es describe-reserved-elasticsearch-instances`.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
