Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I download selective date range files from S3 bucket based on given date range like 08th aug to 15 Aug using AWS CLI?

I am able to filter a particular date's data but not the date range data. Like 12-09-2019 to 15-09-2019 using AWS CLI

eg. to filter 2019 year's data i am using --recursive --exclude "*" --include "2019"

like image 769
himanshika yaduvanshi Avatar asked Jan 01 '26 03:01

himanshika yaduvanshi


1 Answers

You will need to use the s3api to handle the query which uses the JMESPath syntax

aws s3api list-objects-v2 --bucket BUCKET --query "Contents[?(LastModified>='2019-09-12' && LastModified<='2019-09-15')].Key"

You can also specify time as well

aws s3api list-objects-v2 --bucket BUCKET --query "Contents[?(LastModified>='2019-09-12T12:00:00.00Z' && LastModified<='2019-09-15T12:00:00.00Z')].Key"

The downside to this approach is that it must list every object and perform the query. For large buckets if you can limit to a prefix it will speed up your search.

aws s3api list-objects-v2 --bucket BUCKET --prefix PREFIX --query "Contents[?(LastModified>='2019-09-12T12:00:00.00Z' && LastModified<='2019-09-15T12:00:00.00Z')].Key"

And if your primary lookup is by date then look to store the objects in date/time sort order as you can use the prefix option to speed up your searches. A couple of examples.

prefix/20190615T041019Z.json.gz
2019/06/15/T041019Z.json.gz

This will

like image 130
WaltDe Avatar answered Jan 04 '26 22:01

WaltDe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!