less than 1 minute read

AWS CLI Commands

S3 Buckets

1
2
3
# Search S3 bucket for a file containing the string ${i}
$ echo ${i}
        aws s3api list-objects --bucket trust-power-consent-register-bucket-prod --prefix "live/-prod" --query "Contents[?contains(Key, '${i}')]" 
1
2
3
4
5
# Find all files with a specific modified date.
DATE=$(date +%Y-%m-%d)
bucket=test-bucket-fh
aws s3api list-objects-v2 --bucket "$bucket" \
    --query 'Contents[?contains(LastModified, `'"$DATE"'`)]'
1
2
3
4
5
6
# Find files after a certain date
SINCE=`date --date '-2 weeks +2 days' +%F 2>/dev/null || date -v '-2w' -v '+2d' +%F`
#      ^^^^ GNU style                                    ^^^^ BSD style
bucket=test-bucket-fh
aws s3api list-objects-v2 --bucket "$bucket" \
    --query 'Contents[?LastModified > `'"$SINCE"'`]'
1
2
# Find files from certain date to current date
aws s3api list-objects-v2 --bucket BUCKET_NAME  --query 'Contents[?LastModified>=`YYYY-MM-DD`].Key'