AWS Introduction
AWS Pricing
AWS Threats
AWS Misconfigurations
- Getting Started with AWS Audit
- Permissions required for Misconfigurations Detection
- API Gateway Audit
- Cloudformation Audit
- CloudFront Audit
- CloudTrail Audit
- Cloudwatch Audit
- DynamoDB Audit
- EC2 Audit
- Elastic Search Audit
- ELB Audit
- IAM Audit
- KMS Audit
- Kubernetes Audit
- Lambda Audit
- RDS Audit
- Redshift Audit
- Route53 Audit
- S3 Audit
- Security Groups Audit
- SES Audit
- SNS Audit
- IAM Deep Dive
- App Sync Audit
- Code Build Audit
- Open Search Audit
- Shield Audit
- SQS Audit
Reserved Instance Lease Expiration In The Next 30 Days
More Info:
Lists all EC2 reserved instances expiring in the next 30 days.
Risk Level
Low
Address
Cost Optimisation
Compliance Standards
CBP
Triage and Remediation
Remediation
When you receive a notification that your AWS Reserved Instances are expiring in the next 30 days, you need to take action to prevent any disruptions to your AWS resources. Here are the steps to remediate this issue using the AWS console:
- Log in to your AWS Management Console.
- Navigate to the EC2 dashboard.
- Click on the “Reserved Instances” link in the left-hand navigation menu.
- In the “Reserved Instances” page, you will see a list of all your reserved instances. Look for the ones that are expiring in the next 30 days.
- Select the reserved instances that are expiring soon and click on the “Actions” button.
- From the drop-down menu, select “Modify Reserved Instances”.
- In the “Modify Reserved Instances” page, you can modify the instance type, availability zone, and the number of instances you want to reserve.
- Once you have made the necessary changes, click on the “Modify” button to save the changes.
- After modifying the reserved instances, you will receive a confirmation message that the changes have been made.
By following these steps, you will be able to remediate the issue of Reserved Instance Lease Expiration in the next 30 days for AWS.
The “Reserved Instance Lease Expiration In The Next 30 Days” issue in AWS means that some of your Reserved Instances are about to expire. To remediate this issue, you can follow the below steps using AWS CLI:
-
Open your terminal and ensure that you have the AWS CLI installed and configured with your AWS account credentials.
-
Run the following command to list all the Reserved Instances that are about to expire in the next 30 days:
aws ec2 describe-reserved-instances --filters "Name=state,Values=active" "Name=product-description,Values=Linux/UNIX (Amazon VPC)" "Name=scope,Values=Availability Zone" --query 'ReservedInstances[?End <= `'"$(date -u +'%Y-%m-%dT%H:%M:%S.000Z' -d '+30 days')"']'
This command will list all the active Reserved Instances that are running Linux/UNIX in Amazon VPC and are scoped to Availability Zone, and whose lease is expiring in the next 30 days.
-
Review the output and identify the Reserved Instances that you want to renew. Note down the Reserved Instance ID(s) that you want to renew.
-
Run the following command to purchase a new Reserved Instance with the same specifications and lease term as the expiring Reserved Instance:
aws ec2 purchase-reserved-instances-offering --instance-count [COUNT] --reserved-instances-offering-id [OFFERING_ID] --dry-run
Replace [COUNT] with the number of instances you want to reserve, [OFFERING_ID] with the ID of the offering that matches the expiring Reserved Instance, and —dry-run with —no-dry-run to actually purchase the Reserved Instance.
- Verify that the new Reserved Instance is active and that the old Reserved Instance has been retired by running the following command:
aws ec2 describe-reserved-instances --reserved-instances-ids [OLD_INSTANCE_ID] [NEW_INSTANCE_ID]
Replace [OLD_INSTANCE_ID] with the ID of the expiring Reserved Instance and [NEW_INSTANCE_ID] with the ID of the newly purchased Reserved Instance.
- Once you have verified that the new Reserved Instance is active, you can terminate the old Reserved Instance by running the following command:
aws ec2 modify-reserved-instances --reserved-instances-id [OLD_INSTANCE_ID] --target-configurations "InstanceCount=0"
Replace [OLD_INSTANCE_ID] with the ID of the expiring Reserved Instance.
By following the above steps, you can remediate the “Reserved Instance Lease Expiration In The Next 30 Days” issue in AWS using AWS CLI.
To remediate the issue of Reserved Instance Lease Expiration In The Next 30 Days in AWS using Python, you can follow these steps:
- Import the required libraries:
import boto3
from datetime import datetime, timedelta
- Create a connection to the AWS EC2 service:
ec2 = boto3.client('ec2')
- Retrieve the list of Reserved Instances with lease expiration dates within the next 30 days:
now = datetime.now()
filters = [{'Name': 'state', 'Values': ['active']},
{'Name': 'instance-state-name', 'Values': ['running', 'stopped']},
{'Name': 'end', 'Values': [str(now + timedelta(days=30)).split()[0]]}]
reserved_instances = ec2.describe_reserved_instances(Filters=filters)
- For each Reserved Instance, check if its lease expiration date is within the next 30 days and if so, modify its lease to extend it:
for reserved_instance in reserved_instances['ReservedInstances']:
end_date = datetime.strptime(reserved_instance['End'], '%Y-%m-%dT%H:%M:%S.%fZ')
if (end_date - now).days <= 30:
ec2.modify_reserved_instances(
ReservedInstancesIds=[reserved_instance['ReservedInstancesId']],
ClientToken=str(datetime.now().strftime('%Y%m%d%H%M%S')),
TargetConfigurations=[
{
'AvailabilityZone': reserved_instance['AvailabilityZone'],
'InstanceCount': reserved_instance['InstanceCount'],
'InstanceType': reserved_instance['InstanceType'],
'Platform': reserved_instance['ProductDescription'],
'Scope': 'Availability Zone',
'Tenancy': reserved_instance['InstanceTenancy']
}
]
)
- Run the Python script on a regular basis (e.g. daily) using a scheduler like cron to ensure that Reserved Instances are always extended before their lease expires.
Note: This code is provided as an example only and should be tested and modified to suit your specific requirements. It is also important to ensure that you have the necessary permissions to modify Reserved Instances in your AWS account.