Ad

List All EC2 EBS Snapshots Taken On A Particular Date

I am trying to list all EBS volume snapshot which is taken on a particular date so that i can automate a copy via bash script across region for better disaster recovery I have an another bash script that creates snapshots of all in use EBS volumes and delete all which is older then 30 days. I need to copy all which is taken on a previous date across an another region.

I tried many jmespath switches (which is not giving any output) some of them are as:-

$aws ec2 describe-snapshots --query 'Sanpshots[?StartTime >= `2018-06-25`]|[?StartTime <= `2018-06-27`]'
$aws ec2 describe-snapshots --query 'Sanpshots[?StartTime == `2018-06-25`]

I looked many pages but not able to find for a particular date listing. Please suggest some switches,sorting methods,links or anything. Thanks.

Ad

Answer

I Figured the JMESpath switch from doc right here. So in order to search for a particular date i applied a switch which search between two dates. for example:-

'Snapshots[?(StartTime >= `2018-06-27`) && (StartTime <= `2018-06-28`)]

Reason why "==" is not working in the switch as it used for exact match string.

So the complete string is :-

aws ec2 describe-snapshots --query 'Snapshots[?(StartTime >= `2018-06-27`) && (StartTime <= `2018-06-28`)].{ID:SnapshotId,ST:StartTime}' --output text --region $regionname
Ad
source: stackoverflow.com
Ad