Using only the AWS CLI, you can run a list-objects
against the bucket with the --query
parameter. This will not be a fast operation, as it runs locally after fetching the file list, rather than inside s3's api.
$ aws s3api list-objects --bucket bucket-name --query "Contents[?contains(Key, 'file3')]"
[
{
"LastModified": "2017-05-31T20:36:28.000Z",
"ETag": "\"b861daa5cc3775f38519f5de6566cbe7\"",
"StorageClass": "STANDARD",
"Key": "00002/file3.doc",
"Owner": {
"DisplayName": "owner",
"ID": "123"
},
"Size": 27032
}
]
The benefit of using --query
over just piping to grep is that you'll get the full response including all available metadata usually included in list-objects
, without having to monkey around with before and after arguments for the grep.
See this post on Finding Files in S3 for further information including a similar example which shows the benefit of having metadata, when files of the same name end up in different directories.