library
turbot/aws_thrifty

Detect & correct RDS DB instances with low connection count

Overview

RDS instances can be costly to run, especially if they're rarely used, instances with low average connection counts per day should be reviewed to determine if they're still required.

This query trigger detects RDS instances with low average daily connections and then either sends a notification or attempts to perform a predefined corrective action.

Getting Started

By default, this trigger is disabled, however it can be configred by setting the below variables

  • rds_db_instances_with_low_connection_count_trigger_enabled should be set to true as the default is false.
  • rds_db_instances_with_low_connection_count_trigger_schedule should be set to your desired running schedule
  • rds_db_instances_with_low_connection_count_default_action should be set to your desired action (i.e. "notify" for notifications or "delete_instance" to delete the instance).

Then starting the server:

flowpipe server

or if you've set the variables in a .fpvars file:

flowpipe server --var-file=/path/to/your.fpvars

Query

with rds_db_usage as (
select
db_instance_identifier,
round(sum(maximum) / count(maximum)) as avg_max,
region,
account_id,
_ctx
from
aws_rds_db_instance_metric_connections_daily
where
date_part('day', now() - timestamp) <= 30
group by
db_instance_identifier,
region,
account_id,
_ctx
)
select
concat(
db_instance_identifier,
' [',
region,
'/',
account_id,
']'
) as title,
db_instance_identifier,
region,
_ctx ->> 'connection_name' as cred
from
rds_db_usage
where
avg_max = 0

Schedule

15m