01 Run describe-instances command (OSX/Linux/UNIX) using custom query filters to list the identifiers of all the existing RDS instances available in the selected region:
aws rds describe-db-instances
--region us-east-1
--output table
--query 'DBInstances[*].DBInstanceIdentifier
02 The command output should return a table with the requested database names:
-------------------------
| DescribeDBInstances |
+-----------------------+
| cc-mysqldb-staging |
| cc-mariadb-ver-2.4 |
| cc-mariadb-ver-1.9 |
+-----------------------+
03 Run get-metric-statistics command (OSX/Linux/UNIX) to get the statistics recorded by AWS CloudWatch for the DatabaseConnections metric, representing the number of RDS database connections in use. Change the --start-time (start recording date) and --end-time (stop recording date) parameters value to choose your own time frame for recording the DatabaseConnections usage. Also, set the --period parameter value to define the granularity - in seconds - of the returned datapoints, based on your requirements. A period can be as short as one minute (60 seconds) or as long as one day (86400 seconds). The following command example returns the average database connections usage of an AWS RDS instance identified by the the name cc-mysql-database, usage data captured during a 7 days period (set by the --start-time and --end-time command parameters), using 1 hour period as the granularity of the returned datapoints (set by the --period parameter):
aws cloudwatch get-metric-statistics
--region us-east-1
--metric-name DatabaseConnections
--start-time 2016-10-04T13:16:00
--end-time 2016-10-11T13:16:00
--period 3600
--namespace AWS/RDS
--statistics Average
--dimensions Name=DBInstanceIdentifier,Value=cc-mysql-database
04 The command output should return the DatabaseConnections usage details requested:
{
"Datapoints": [
{
"Timestamp": "2016-10-04T13:16:00Z",
"Average": 0.0,
"Unit": "Count"
},
{
"Timestamp": "2016-10-04T14:16:00Z",
"Average": 0.011,
"Unit": "Count"
},
{
"Timestamp": "2016-10-04T15:16:00Z",
"Average": 0.0125,
"Unit": "Count"
},
...
{
"Timestamp": "2016-10-11T10:16:00Z",
"Average": 0.02283333333333333,
"Unit": "Count"
},
{
"Timestamp": "2016-10-11T11:16:00Z",
"Average": 0.01664,
"Unit": "Count"
},
{
"Timestamp": "2016-10-11T12:16:00Z",
"Average": 0.0313333333333333,
"Unit": "Count"
}
],
"Label": "DatabaseConnections"
}
If the average number of database connections has been less than 1 for the last 7 days, the selected RDS instance qualifies as candidate for the idle instance.
05 Run again get-metric-statistics command (OSX/Linux/UNIX) to get the statistics recorded by AWS CloudWatch for the ReadIOPS metric, representing the number of Read I/O operations per second. The following command example returns the total number of ReadIOPS used by an AWS RDS instance identified by the the name cc-mysql-database, IOPS usage data captured during a 7 days period (set by the --start-time and --end-time command parameters), using 1 hour period as the granularity of the returned datapoints (set by the --period parameter):
aws cloudwatch get-metric-statistics
--region us-east-1
--metric-name ReadIOPS
--start-time 2016-10-04T13:16:35
--end-time 2016-10-11T13:16:35
--period 3600
--namespace AWS/RDS
--statistics Sum
--dimensions Name=DBInstanceIdentifier,Value=cc-mysql-database
06 The command output should return the ReadIOPS usage details requested:
{
"Datapoints": [
{
"Timestamp": "2016-10-04T13:16:35Z",
"Sum": 0.23400416762398904,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-04T14:16:35Z",
"Sum": 1.4499758337361044,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-04T15:16:35Z",
"Sum": 0.0,
"Unit": "Count/Second"
},
...
{
"Timestamp": "2016-10-11T10:16:35Z",
"Sum": 1.0999450027498625,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-11T11:16:35Z",
"Sum": 0.0,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-11T12:16:35Z",
"Sum": 1.1000366678889297,
"Unit": "Count/Second"
}
],
"Label": "ReadIOPS"
}
If the total number of ReadIOPS has been less than 20 for the last 7 days, the selected RDS instance qualifies as candidate for the idle instance.
07 Run get-metric-statistics command (OSX/Linux/UNIX) to get the statistics recorded by AWS CloudWatch for the WriteIOPS metric, representing the number of Write I/O operations per second. The following command example returns the total number of WriteIOPS used by an AWS RDS instance identified by the name cc-mysql-database, IOPS usage data captured during a 7 days period (set by the --start-time and --end-time command parameters), using 1 hour period as the granularity of the returned datapoints (set by the --period parameter):
aws cloudwatch get-metric-statistics
--region us-east-1
--metric-name WriteIOPS
--start-time 2016-10-04T13:16:57
--end-time 2016-10-11T13:16:57
--period 3600
--namespace AWS/RDS
--statistics Sum
--dimensions Name=DBInstanceIdentifier,Value=cc-mysql-database
08 The command output should return the WriteIOPS usage details requested:
{
"Datapoints": [
{
"Timestamp": "2016-10-04T13:16:57Z",
"Sum": 0.09999166736105325,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-04T14:16:57Z",
"Sum": 0.15,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-04T15:16:57Z",
"Sum": 0.25000416673611225,
"Unit": "Count/Second"
},
...
{
"Timestamp": "2016-10-11T10:16:57Z",
"Sum": 0.10000333344444814,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-11T11:16:57Z",
"Sum": 0.2500125006250313,
"Unit": "Count/Second"
},
{
"Timestamp": "2016-10-11T12:16:57Z",
"Sum": 0.6833561118703957,
"Unit": "Count/Second"
}
],
"Label": "WriteIOPS"
}
If the total number of WriteIOPS has been less than 20 for the last 7 days, the selected RDS instance qualifies as candidate for the idle instance.
09 Run list-tags-for-resource command (OSX/Linux/UNIX) to list the existing tags for the selected RDS instance:
aws rds list-tags-for-resource
--region us-east-1
--resource-name arn:aws:rds:us-east-1:123456789012:db:cc-mysql-database
10 The command output should return the tags (key-value pairs) applied to the instance. The Role and Owner tags returned and their values (highlighted) can be used to determine the resource role within the application stack and to contact its owner for more information in order to decide whether the RDS database instance can be terminated or not:
{
"TagList": [
{
"Value": "legacy-app-db-test-server",
"Key": "Role"
},
{
"Value": "db_ops@cloudconformity.com",
"Key": "Owner"
},
{
"Value": "legacy-webapp-db",
"Key": "Name"
}
]
}
If the data returned for the steps no. 3 - 10 satisfy the conditions set by the conformity rule (instance role, instance owner, ReadIOPS + WriteIOPS, database connections), the selected RDS instance is considered "idle" and can be terminated in order to reduce AWS RDS usage costs.
11 Repeat steps no. 3 - 10 to verify the role, owner, DatabaseConnections, ReadIOPS and WriteIOPS metrics usage within the specified time frame for the rest of the RDS instances available in the current region.
12 Change the AWS region by updating the --region command parameter value and repeat steps no. 1 - 11 to perform the audit process for other regions.