AWS Config records the configuration history for AWS resources and checks their compliance against defined config rules. This allows us to identify unused EBS volumes, for example, which is crucial for controlling costs associated with unused resources. We can use Advanced queries to get more data out of AWS Config as shown below
EBS Unused Volumes query:
This query retrieves a list of unused EC2 volumes that are not attached to any EC2 instances. Note that the default root volume created for an instance is always deleted when the instance is deleted. This query will only display other volumes that are not currently attached to any instance
SELECT
resourceId,
resourceType,
configuration.volumeType,
configuration.size,
resourceCreationTime,
tags,
configuration.encrypted,
configuration.availabilityZone,
configuration.state.value
WHERE
resourceType = 'AWS::EC2::Volume'
AND configuration.state.value <> 'in-use'
This query can be executed under Advanced queries under AWS Config and once you execute this query, you should be able to see the list of unattached volumes as shown below
The above list shows 2 volumes that is not attached to any EC2 instances (This list won’t show root volumes attached to an EC2 instance as the root volume will be always deleted whenever an EC2 instance is terminated in AWS)
Clicking on the resourceid will further show the details of the EC2 EBS Volume as shown below sycg as Resource Name, Resource Type, Resource ID, Availability Zone, Volume Type, State and IOPS etc.,
To look into more details, scroll below and expand View Configuration item by JSON (This will show all the details that are related with the particular volume)