I need to list all objects with a certain last modified date in a directory within my S3 bucket using the aws s3api. I have the following:
aws s3api list-objects-v2 --bucket 's3://my-bucket/dir1/dir2/dir3' --query 'Contents[?contains(LastModified, `2023-01-08`)].Key'
This fails due to the forward slashes in the path not being allowed. I believe I need to add the path to directory using a key value but can't find an example anywhere of how to do it. Can somebody please help?
You need to supply the bucket name and S3 object key prefix independently, for example:
aws s3api list-objects-v2 \
--bucket my-bucket \
--prefix dir1/dir2/dir3/ \
--query 'Contents[?contains(LastModified, `2023-01-08`)].Key'