AWS-SDK: Query parameter in listobjects of S3


I want to fetch objects after a particular date. Using the AWS CLI I can list objects using below command:

aws s3api list-objects-v2 --bucket "bucket1" --prefix "file-" --query "(Contents[?LastModified>'2019-02-06T05:34:12.000Z'])[0]"

But I want to do it from my code so please let me know how can I filter objects usin NPM AWS-SDK.

Note: I can do it using exec or spawn but for this I have to configure profile using CLI which will create credential file on local so I dont want to do this.


Use the AWS SDK for node.js. Call the listObjectsV2 method and then use jmespath.js in the callback method to filter the output of the API call. This is the equivalent of what the AWS CLI does via the --query param.

Something like this (untested)

Leave a Reply