01 Run describe-volumes command (OSX/Linux/UNIX) using custom query filters based on query language (integrated by AWS CLI), to list the IDs of all non-root, running (i.e. in use) EBS volumes, available within the selected region:
aws ec2 describe-volumes
--region us-east-1
--filters Name=status,Values=in-use
--output table
--query 'Volumes[].Attachments[?(Device!=`/dev/xvda`) && (Device!=`/dev/sda1`)].VolumeId | []'
02 The command output should return a table with the requested volume IDs:
---------------------------
| DescribeVolumes |
+-------------------------+
| vol-05fd4936c6b5bc413 |
| vol-0c005f19fa4ac7c0e |
| vol-0acb9f6580f38caf5 |
+-------------------------+
03 Run get-metric-statistics command (OSX/Linux/UNIX) to get the statistics recorded by AWS CloudWatch for the VolumeReadOps metric representing the EBS volume read throughput. The following command example returns the total read throughput usage captured within the 7-day time frame for an EBS volume identified by the ID vol-05fd4936c6b5bc413, using 1 hour as the granularity for the returned datapoints:
aws cloudwatch get-metric-statistics
--region us-east-1
--metric-name VolumeReadOps
--start-time 2017-03-04T12:15:00
--end-time 2017-03-11T12:15:00
--period 3600
--namespace AWS/EBS
--statistics Sum
--dimensions Name=VolumeId,Value=vol-05fd4936c6b5bc413
04 The command output should return the volume read throughput usage data requested:
{
"Datapoints": [
{
"Timestamp": "2017-03-04T12:15:00Z",
"Sum": 0.1050,
"Unit": "Count"
},
{
"Timestamp": "2017-03-04T13:15:00Z",
"Sum": 0.10425,
"Unit": "Count"
},
{
"Timestamp": "2017-03-04T14:15:00Z",
"Sum": 0.033499999999999995,
"Unit": "Count"
},
...
{
"Timestamp": "2017-03-11T10:15:00Z",
"Sum": 0.027833333333333333,
"Unit": "Count"
},
{
"Timestamp": "2017-03-11T11:15:00Z",
"Sum": 0.033499999999999995,
"Unit": "Count"
},
{
"Timestamp": "2017-03-11T12:15:00Z",
"Sum": 0.033799999999999995,
"Unit": "Count"
}
],
"Label": "VolumeReadOps"
}
If the total number of VolumeReadOps has been less than 1 (one), the selected EBS volume qualifies as candidate for the idle volume.
05 Run again get-metric-statistics command (OSX/Linux/UNIX) to retrieve the statistics recorded by Amazon CloudWatch service for the VolumeWriteOps metric, representing the EBS volume write throughput. The following command example returns the total write throughput usage recorded within the 7-day time frame for an EBS volume identified by the ID vol-05fd4936c6b5bc413, using 1 hour as the granularity for the returned datapoints:
aws cloudwatch get-metric-statistics
--region us-east-1
--metric-name VolumeWriteOps
--start-time 2017-03-04T12:15:00
--end-time 2017-03-11T12:15:00
--period 3600
--namespace AWS/EBS
--statistics Sum
--dimensions Name=VolumeId,Value=vol-05fd4936c6b5bc413
06 The command output should return the volume write throughput usage details requested:
{
"Datapoints": [
{
"Timestamp": "2017-03-04T12:15:00Z",
"Sum": 0.0,
"Unit": "Count"
},
{
"Timestamp": "2017-03-04T13:15:00Z",
"Sum": 0.0,
"Unit": "Count"
},
{
"Timestamp": "2017-03-04T14:15:00Z",
"Sum": 0.0,
"Unit": "Count"
},
...
{
"Timestamp": "2017-03-11T10:15:00Z",
"Sum": 0.056733333333333333,
"Unit": "Count"
},
{
"Timestamp": "2017-03-11T11:15:00Z",
"Sum": 0.054099999999999995,
"Unit": "Count"
},
{
"Timestamp": "2017-03-11T12:15:00Z",
"Sum": 0.038999999999999995,
"Unit": "Count"
}
],
"Label": "VolumeWriteOps"
}
If the total number of VolumeWriteOps has been less than 1, the selected EBS volume qualifies as candidate for idleness.
07 Run describe-tags command (OSX/Linux/UNIX) to describe the tags for the selected EBS volume. These tags are used to determine the volume role within your application stack (e.g. staging-server-block-volume) in order to decide whether it's safe or not to delete the volume:
aws ec2 describe-tags
--region us-east-1
--filters "Name=resource-id,Values=vol-05fd4936c6b5bc413"
08 The command output should return the EBS volume tags available. Check for any "Role" or Role-like tags to determine the volume usage profile:
{
"Tags": [
{
"ResourceType": "volume",
"ResourceId": "vol-05fd4936c6b5bc413",
"Value": "Staging",
"Key": "Environment"
},
{
"ResourceType": "volume",
"ResourceId": "vol-05fd4936c6b5bc413",
"Value": "cc-webapp-server-volume",
"Key": "Name"
},
{
"ResourceType": "volume",
"ResourceId": "vol-05fd4936c6b5bc413",
"Value": "staging-server-block-volume",
"Key": "Role"
}
]
}
If the data returned for the steps no. 3 - 8 satisfy the conformity rule conditions (i.e. total read/write throughput usage recorded within a week), the selected EBS volume is considered "idle" and can be safely removed from the AWS account to reduce the EBS monthly costs.
09 Repeat steps no. 3 – 8 to verify the usage profile and the associated CloudWatch metrics (VolumeReadOps and VolumeWriteOps) for other EBS volumes provisioned within the current region.
10 Change the AWS region by updating the --region command parameter value and repeat steps no. 1 - 9 to perform the entire audit process for other regions.