> ## 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 performance insights remediation

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration of the Performance Insights feature not being enabled for an AWS RDS instance using the AWS console, follow these step-by-step instructions:

        1. **Login to AWS Console**: Go to the AWS Management Console and log in with your credentials.

        2. **Navigate to RDS Service**: Click on the "Services" dropdown menu at the top left corner of the console and select "RDS" under the Database category.

        3. **Select the RDS Instance**: From the list of RDS instances, select the instance for which you want to enable Performance Insights by clicking on its identifier.

        4. **Enable Performance Insights**: In the RDS instance details page, scroll down to the "Performance Insights" section in the left-hand menu.

        5. **Click on "Modify"**: Click on the "Modify" button in the Performance Insights section to enable the feature for the selected RDS instance.

        6. **Configure Performance Insights**: In the Modify DB instance page, under the "Performance Insights" section, you can configure the following settings:
           * Enable Performance Insights: Check the box to enable Performance Insights for the RDS instance.
           * Choose the Retention Period: Select the retention period for Performance Insights data.
           * Choose the Monitoring Level: Select the monitoring level for Performance Insights data collection.

        7. **Save Changes**: Scroll down to the bottom of the page and click on the "Continue" button.

        8. **Apply Changes**: Review the changes you are about to make and click on the "Modify DB Instance" button to apply the changes.

        9. **Monitor Performance Insights**: Once the changes are applied, Performance Insights will be enabled for the selected RDS instance. You can now monitor the performance of the RDS instance using the Performance Insights dashboard.

        By following these steps, you can successfully remediate the misconfiguration of the Performance Insights feature not being enabled for an AWS RDS instance using the AWS console.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration of enabling Performance Insights feature for AWS RDS using AWS CLI, follow these steps:

        1. **Enable Performance Insights on an RDS DB instance**:

           Run the following AWS CLI command to enable Performance Insights on an RDS DB instance:

           ```bash theme={null}
           aws rds modify-db-instance --db-instance-identifier your-db-instance-name --enable-performance-insights
           ```

           Replace `your-db-instance-name` with the actual name of your RDS DB instance.

        2. **Verify Performance Insights is enabled**:

           You can verify if Performance Insights is enabled for the DB instance by describing the DB instance using the following command:

           ```bash theme={null}
           aws rds describe-db-instances --db-instance-identifier your-db-instance-name --query 'DBInstances[0].PerformanceInsightsEnabled'
           ```

           Replace `your-db-instance-name` with the actual name of your RDS DB instance.

        3. **Access Performance Insights**:

           Once Performance Insights is enabled, you can access it through the AWS Management Console or AWS CLI to monitor the performance of your RDS DB instance.

        By following these steps, you should be able to remediate the misconfiguration of enabling the Performance Insights feature for your AWS RDS DB instance using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration of enabling the Performance Insights feature for an AWS RDS instance using Python, you can use the AWS SDK for Python (Boto3). Below are the step-by-step instructions to enable the Performance Insights feature for an AWS RDS instance:

        1. Install Boto3:
           Ensure that you have the Boto3 library installed in your Python environment. You can install Boto3 using pip:

        ```bash theme={null}
        pip install boto3
        ```

        2. Configure AWS Credentials:
           Make sure that you have configured your AWS credentials with the necessary permissions to modify the RDS instance. You can set up your AWS credentials by either setting environment variables or using the AWS CLI `aws configure` command.

        3. Write Python Script:
           Create a Python script with the following code to enable the Performance Insights feature for the desired RDS instance:

        ```python theme={null}
        import boto3

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

        # Specify the RDS instance identifier
        db_instance_identifier = 'your_rds_instance_identifier'

        # Enable Performance Insights for the RDS instance
        response = rds_client.modify_db_instance(
            DBInstanceIdentifier=db_instance_identifier,
            EnablePerformanceInsights=True,
            PerformanceInsightsKMSKeyId='your_kms_key_id',  # Optional
            PerformanceInsightsRetentionPeriod=7  # Optional, in days
        )

        print(response)
        ```

        Replace `'your_rds_instance_identifier'` with the actual identifier of your RDS instance. You can also specify the KMS key ID and retention period according to your requirements.

        4. Run the Script:
           Execute the Python script in your terminal or IDE. This will make an API call to AWS to modify the RDS instance and enable the Performance Insights feature.

        After running the script successfully, the Performance Insights feature should be enabled for the specified RDS instance.

        Please ensure that you have the necessary permissions to modify the RDS instance and enable the Performance Insights feature.
      </Accordion>

      <Accordion title="Using Terraform">
        ```hcl theme={null}
        resource "aws_db_instance" "RDS_INSTANCE" {
          # Replace with your existing configuration
          identifier = "DB_INSTANCE_IDENTIFIER" # RDS DB instance identifier

          engine         = "mysql"              # or "postgres"
          instance_class = "db.t3.medium"
          allocated_storage = 20
          username          = "DB_USERNAME"
          password          = "DB_PASSWORD"
          db_subnet_group_name = aws_db_subnet_group.DB_SUBNET_GROUP.name

          # Enable Performance Insights (matches the CLI: --enable-performance-insights)
          performance_insights_enabled = true

          # Optional: to match CLI default 7-day retention, either omit or explicitly set:
          # performance_insights_retention_period = 7

          # Apply immediately, like the CLI's --apply-immediately flag
          apply_immediately = true

          # ...other existing arguments...
        }
        ```

        Enabling `performance_insights_enabled` on an existing `aws_db_instance` updates the instance in-place (no replacement), but it will modify the running database; schedule during a maintenance window as needed and be aware of potential additional costs for Performance Insights.

        For verification, `terraform plan` should show an in-place update to the existing `aws_db_instance` with `performance_insights_enabled` changing from `false` (or `null`) to `true` (and, if you set it, `performance_insights_retention_period` to the desired value).
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
