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

# Rds deprecated versions in use remediation

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the issue of using deprecated RDS versions in AWS, follow these steps using the AWS Management Console:

        1. **Identify the RDS Instances with Deprecated Versions:**
           * Log in to your AWS Management Console.
           * Navigate to the RDS service.
           * Click on "Databases" from the left-hand menu.
           * Look for databases that are using deprecated RDS versions. These instances will be marked with a warning sign indicating that the version is deprecated.

        2. **Create a Snapshot of the RDS Instance:**
           * Before performing any upgrade, it is recommended to create a snapshot of your RDS instance for backup purposes.
           * Select the RDS instance that you want to upgrade.
           * Click on the "Instance actions" dropdown menu.
           * Select "Take snapshot" and provide a name for the snapshot.

        3. **Modify the RDS Instance:**
           * Select the RDS instance that you want to upgrade.
           * Click on the "Modify" button.
           * In the Modify RDS Instance window, select the desired RDS engine version that is supported and not deprecated.
           * Review the other configuration settings if needed.
           * Click on the "Continue" button.

        4. **Apply the Changes:**
           * Review the changes you made in the Modify RDS Instance window.
           * Scroll down and click on the "Modify DB Instance" button to apply the changes.
           * AWS will schedule a maintenance window for the upgrade process. The actual upgrade will happen during this maintenance window.

        5. **Monitor the Upgrade Process:**
           * Once the maintenance window starts, AWS will automatically upgrade the RDS instance to the new version.
           * Monitor the upgrade process from the RDS console to ensure that it completes successfully.

        6. **Verify the Upgrade:**
           * After the upgrade process is completed, verify that the RDS instance is now running on the new, non-deprecated version.
           * Test your applications to ensure that they are working as expected with the upgraded RDS instance.

        By following these steps, you can remediate the issue of using deprecated RDS versions in AWS and ensure that your RDS instances are running on supported and up-to-date versions.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the issue of using deprecated RDS versions in AWS RDS using AWS CLI, you can follow these steps:

        1. List all the RDS instances and their engine versions currently in use:

        ```
        aws rds describe-db-instances
        ```

        2. Identify the RDS instances that are using deprecated engine versions. You can refer to the AWS RDS documentation to check for the latest supported engine versions.

        3. Create a snapshot of the RDS instance that is using the deprecated engine version:

        ```
        aws rds create-db-snapshot --db-instance-identifier <your-db-instance-name> --db-snapshot-identifier <snapshot-name>
        ```

        4. Delete the RDS instance that is using the deprecated engine version:

        ```
        aws rds delete-db-instance --db-instance-identifier <your-db-instance-name> --skip-final-snapshot
        ```

        5. Create a new RDS instance with the latest supported engine version using the snapshot created earlier:

        ```
        aws rds restore-db-instance-from-db-snapshot --db-instance-identifier <new-db-instance-name> --db-snapshot-identifier <snapshot-name> --db-instance-class <instance-type> --engine <engine-type>
        ```

        6. Update any necessary configurations or settings on the new RDS instance as per your requirements.

        7. Test the new RDS instance to ensure that it is functioning correctly with the latest supported engine version.

        By following these steps, you can successfully remediate the issue of using deprecated RDS versions in AWS RDS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the issue of using deprecated RDS versions in AWS using Python, you can follow these steps:

        1. **Identify the deprecated RDS versions in use**:
           * Use the AWS SDK for Python (Boto3) to list all the RDS instances in your account.
           * Check the engine version of each RDS instance against the list of deprecated versions provided by AWS.

        2. **Upgrade the RDS instances**:
           * For each RDS instance using a deprecated version, create a snapshot of the instance.
           * Modify the RDS instance to upgrade to a supported version using the `modify_db_instance` method in Boto3.
           * Wait for the modification to be completed before proceeding to the next step.

        3. **Test the upgraded RDS instances**:
           * Verify that the RDS instances are functioning correctly after the upgrade.
           * Check if any applications or services relying on these RDS instances are working as expected.

        4. **Cleanup**:
           * Once you have confirmed that all RDS instances have been successfully upgraded, you can delete the snapshots created in step 2 to save costs and reduce clutter in your account.

        Here is a sample Python script to help you get started:

        ```python theme={null}
        import boto3

        # Initialize the RDS client
        rds_client = boto3.client('rds')

        # List all RDS instances
        response = rds_client.describe_db_instances()

        # Deprecated RDS versions provided by AWS
        deprecated_versions = ['your_deprecated_version_1', 'your_deprecated_version_2']

        for db_instance in response['DBInstances']:
            # Check if the RDS instance is using a deprecated version
            if db_instance['EngineVersion'] in deprecated_versions:
                # Create a snapshot of the RDS instance
                snapshot_response = rds_client.create_db_snapshot(
                    DBInstanceIdentifier=db_instance['DBInstanceIdentifier'],
                    DBSnapshotIdentifier=f"{db_instance['DBInstanceIdentifier']}-snapshot"
                )
                
                # Modify the RDS instance to upgrade to a supported version
                rds_client.modify_db_instance(
                    DBInstanceIdentifier=db_instance['DBInstanceIdentifier'],
                    EngineVersion='your_supported_version'
                )
                
                print(f"Upgrading RDS instance {db_instance['DBInstanceIdentifier']} to a supported version...")
                # You can add additional checks here to wait for the modification to be completed

        print("All RDS instances using deprecated versions have been upgraded.")
        ```

        Make sure to replace `'your_deprecated_version_1'`, `'your_deprecated_version_2'`, and `'your_supported_version'` with the actual deprecated and supported RDS versions provided by AWS.

        Run this script in your AWS environment to remediate the issue of using deprecated RDS versions.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "aws_db_parameter_group" "NEW_PARAMETER_GROUP" {
          name        = "NEW_PARAMETER_GROUP_NAME" # replace with a new, engine-compatible parameter group name
          family      = "ENGINE_FAMILY_FOR_NEW_VERSION" # e.g. "postgres16", "mysql8.0", etc.
          description = "Parameter group for upgraded engine version"

          # Add parameter blocks here as needed for your engine/version.
        }

        resource "aws_db_instance" "THIS_DB" {
          identifier = "DB_INSTANCE_IDENTIFIER" # replace with the existing DB instance identifier

          engine         = "ENGINE_NAME"         # e.g. "postgres", "mysql", "aurora-postgresql"
          engine_version = "NEW_ENGINE_VERSION"  # replace with a non-deprecated target version from describe-db-engine-versions

          # REQUIRED TO MATCH THE VERIFIED CLI FIX:
          allow_major_version_upgrade = true
          apply_immediately           = true  # WARNING: causes an immediate outage during the engine upgrade

          parameter_group_name = aws_db_parameter_group.NEW_PARAMETER_GROUP.name

          # ...include all other required arguments for your existing instance...
          # allocated_storage, instance_class, subnet_group_name, vpc_security_group_ids, etc.
        }
        ```

        Terraform cannot safely express the one-time pre-upgrade snapshot (`aws rds create-db-snapshot`) as a persistent resource without creating new snapshots on every apply; create that snapshot manually (or via a one-off script) before applying this change.

        This change upgrades the existing DB instance in place (no Terraform resource replacement), but `engine_version` plus `apply_immediately = true` will cause a service outage while AWS performs the modification. If you prefer to use the next maintenance window instead, set `apply_immediately = false`.

        `terraform plan` should show an in-place update of `aws_db_instance.THIS_DB`, changing `engine_version` (and possibly `parameter_group_name`, `allow_major_version_upgrade`, and `apply_immediately`) with no `-/+` replacement indicators.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
