Elasticsearch Reserved Instance Lease Expiration In The
More Info:
Your AWS Elasticsearch Reserved Instances (RIs) should be renewed before expiration in order to get a significant discount on the hourly charges.
Risk Level
Low
Address
Cost Optimisation
Compliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Using Console
To remediate the Elasticsearch Reserved Instance Lease Expiration in the next 30 days issue for AWS using the AWS console, follow these steps:
- Login to your AWS console.
- Go to the Elasticsearch service.
- Click on the "Reserved Instances" option in the left-hand menu.
- Identify the Elasticsearch Reserved Instance that is expiring in the next 30 days.
- Click on the "Modify Reserved Instance" button.
- Select the "Extend the term of this Reserved Instance" option.
- Choose the desired term length for the extension.
- Review the changes and click on the "Purchase" button to complete the reservation extension.
By following these steps, you will have successfully remediated the Elasticsearch Reserved Instance Lease Expiration in the next 30 days issue on AWS.
Using CLI
To remediate the Elasticsearch Reserved Instance Lease Expiration issue in AWS using AWS CLI, follow these steps:
-
Open the AWS CLI on your local machine or EC2 instance.
-
Run the following command to list all the Elasticsearch Reserved Instances in your AWS account:
aws es describe-reserved-elasticsearch-instances -
Identify the Reserved Instance that has an expiration date within the next 30 days.
-
Run the following command to modify the Reserved Instance:
aws es modify-reserved-elasticsearch-instance --reserved-elasticsearch-instance-id <Reserved Instance ID> --reserved-elasticsearch-instance-offering-id <New Offering ID>Replace
<Reserved Instance ID>with the ID of the Reserved Instance that needs to be modified, and<New Offering ID>with the ID of the new Elasticsearch Reserved Instance offering that you want to use.Note: You can use the
aws es describe-elasticsearch-instance-type-offeringscommand to list all the Elasticsearch Reserved Instance offerings available in your account. -
Verify that the Reserved Instance has been modified by running the following command:
aws es describe-reserved-elasticsearch-instances --reserved-elasticsearch-instance-id <Reserved Instance ID>Replace
<Reserved Instance ID>with the ID of the Reserved Instance that you modified. -
Repeat steps 3 to 5 for all the Elasticsearch Reserved Instances that have an expiration date within the next 30 days.
By following these steps, you can remediate the Elasticsearch Reserved Instance Lease Expiration issue in AWS using AWS CLI.
Using Python
To remediate the Elasticsearch Reserved Instance Lease Expiration in the next 30 days issue on AWS using Python, you can follow these steps:
- Import the necessary AWS SDK modules in Python:
import boto3
from datetime import datetime, timedelta
- Set up the AWS credentials and region:
session = boto3.Session(
aws_access_key_id='YOUR_ACCESS_KEY',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='YOUR_REGION'
)
- Create an Elasticsearch client:
es_client = session.client('es')
- Retrieve the list of Elasticsearch domains:
domains = es_client.list_domain_names()['DomainNames']
- Loop through each domain and check if there are any reserved instances expiring in the next 30 days:
for domain in domains:
domain_name = domain['DomainName']
reserved_instances = es_client.list_reserved_elasticsearch_instances(
ElasticsearchInstanceType='m4.large.elasticsearch',
MaxResults=100,
NextToken=''
)['ReservedElasticsearchInstances']
for ri in reserved_instances:
expiration_date = ri['StartTime'] + timedelta(days=ri['Duration'])
if expiration_date <= datetime.now() + timedelta(days=30):
print(f"Reserved instance for {domain_name} is expiring on {expiration_date}.")
- To remediate the issue, you can either renew the reserved instance or purchase a new one. To renew the reserved instance, use the following code:
es_client.purchase_reserved_elasticsearch_instance_offering(
ReservedElasticsearchInstanceOfferingId='OFFERING_ID',
ReservationName='RESERVATION_NAME',
InstanceCount=1
)
Replace OFFERING_ID with the ID of the reserved instance offering, and RESERVATION_NAME with a name for the reservation.
- If you want to purchase a new reserved instance, use the following code:
es_client.purchase_reserved_elasticsearch_instance_offering(
ReservedElasticsearchInstanceOfferingId='OFFERING_ID',
InstanceCount=1,
ReservationName='RESERVATION_NAME'
)
Replace OFFERING_ID with the ID of the reserved instance offering, and RESERVATION_NAME with a name for the reservation.
By following these steps, you should be able to remediate the Elasticsearch Reserved Instance Lease Expiration in the next 30 days issue on AWS using Python.
Using Terraform
Terraform cannot currently purchase or renew Amazon Elasticsearch/OpenSearch Reserved Instances; the AWS provider does not expose any resource or data source for es/opensearch Reserved Instances.
You must perform the remediation via CLI or Console as in the verified steps, for example:
# 1. Confirm specs of the expiring RI
aws es describe-reserved-elasticsearch-instances \
--reserved-elasticsearch-instance-id EXISTING_RI_ID \
--region AWS_REGION
# 2. Find matching offerings (type and term)
aws es describe-reserved-elasticsearch-instance-offerings \
--region AWS_REGION \
--elasticsearch-instance-type EXISTING_INSTANCE_TYPE \
--duration EXISTING_DURATION_IN_SECONDS
# 3. Purchase a new RI (this is a financial commitment and not reversible)
aws es purchase-reserved-elasticsearch-instance-offering \
--reserved-elasticsearch-instance-offering-id CHOSEN_OFFERING_ID \
--reservation-name EXISTING_RI_NAME-renewal \
--instance-count EXISTING_INSTANCE_COUNT \
--region AWS_REGION
WARNING: This action creates a new financial commitment; review pricing and terms carefully before running the purchase command. There is no true “renew” API, only purchase of a new RI.
Because there is no Terraform resource for this, terraform plan will show no changes related to Elasticsearch/OpenSearch Reserved Instances.