Search code examples
amazon-web-servicesboto3amazon-rds

How to programmatically retrieve Amazon RDS recommendations?


I'd want to know if my RDS instance is using previous generations types and I found out that Amazon provides an RDS recommendations that includes if an RDS instance is using a previous generation however I can't seem to find the appropriate API to check Amazon's recommendation programmatically

I reviewed botocore3, AWS CLI, and AWS RDS API but I can't seem to find the appropriate command or API for this rds:DescribeRecommendationGroups

What I tried is I use the AWS Management Console to view Amazon RDS Recommendations. and found out that AWS can provide recommendations if an RDS instance is used previous generation through the console, I was trying to look if I can do the same action through AWS CLI or boto3 however I only found out that it is only permission


Solution

  • as of march May 7, 2023, you can see Amazon RDS's provided best practice recommendations for your database instances including if your database instance is using a previous generation type through the management console, it is not supported to get Amazon RDS's recommendations via AWS CLI or AWS SDKs.

    However, I'd create a python script that could check if a database instance used an older generation type and if there is newer generation type. the script will check all of your RDS instances if there are available newer generation type based on the database enginee

    def get_rds_instances():
        """Get all RDS instances"""
        rds = boto3.client('rds')
        db_instances = rds.describe_db_instances()
        for db_instance in db_instances['DBInstances']:
            db_instance_identifier = db_instance['DBInstanceIdentifier']
            new_instance_class = db_instance['DBInstanceClass'][3] + \
                str(int(db_instance['DBInstanceClass'][4]) + 1)
            db_instance_engine = db_instance['Engine']
            check_rds_instance_type(db_instance_identifier,
                                    new_instance_class, db_instance_engine)
    
    
    def check_rds_instance_type(db_instance_identifier: str,
                                db_instance_class: str, db_instance_engine: str):
        """Check if a RDS's instance type is using previous generation instance type"""
        rds = boto3.client('rds')
        orderable_db_instances = rds.describe_orderable_db_instance_options(
            Engine=db_instance_engine, MaxRecords=10000)
        available_instance_classes_query = "{DBInstanceClasses:*[].DBInstanceClass}"
        available_instance_classes = jmespath.search(
            expression=available_instance_classes_query, data=orderable_db_instances)
        new_family_types_query = f"DBInstanceClasses[?contains(@, `{db_instance_class}`) == `true`]"
        new_family_types = jmespath.search(
            expression=new_family_types_query, data=available_instance_classes)