AWS EC2-EBS Problem:
As a associate system administrator I worked on Redhat Linux servers, including user management, permissions, services, and performance monitoring Automated routine administrative tasks using Bash scripting and cron jobs, reducing manual effort by ~30% I am aws certified sysops administrator and Google Certified Cloud Engineer. Determined to transition my career into cloud architect /Cloud Support role
Problem:
We have a lot of AWS EC2 instances and EBS volumes, the description of which volumes we have save to a file with: aws ec2 describe-volumes > aws-volumes.json
To solve this, we need to parse the aws-volumes.json file using jq.
This tool is the industry standard for filtering JSON data in a Linux environment.
The Logical Filter To find the specific volume, we need to match five distinct criteria within the Volumes array:
VolumeType: Must be gp3.
CreateTime: Must be before 2025-09-30 (Note: September only has 30 days, so we will filter for strictly less than Sept 31st or Oct 1st).
Size: Must be less than 64 GiB.
Iops: Must be less than 1500.
Throughput: Must be greater than 300 MB/s.
Solution:
Run the following command in your terminal. It filters the JSON, extracts the InstanceId from the Attachments array, and saves it to your solution file.
cat aws-volumes.json | jq -r '.Volumes[] |
select( .VolumeType == "gp3" and .CreateTime < "2025-09-31" and .Size < 64 and .Iops < 1500 and .Throughput > 300 ) | .Attachments[0].InstanceId' > ~/mysolution
Explanation:
.Volumes[]: Iterates through every volume object in the list.
select(...) Acts as a "Where" clause. It only passes objects that satisfy all your mathematical and string conditions.
.Attachments[0].InstanceId: Since a volume is attached to an instance, this reaches into the attachment metadata to grab the ID.
-r: This is the "raw" output flag for jq, ensuring the resulting string doesn't have double quotes around the ID.
Verification To ensure the solution is correct before finalizing, you can check the hash as requested:
aws ec2 describe-volumes --query 'Volumes[?VolumeType==`gp3` && CreateTime < `2025-09-31`
&& Size < `64` && Iops < `1500` &&
Throughput > `300`].Attachments[0].InstanceId' --output text > ~/mysolution