Reputation: 39
I need to create a job that validates the oldest files in a bucket, after deleting them. I'm new to aws cli. Can someone help me?
OBS: I'm creating in bash.
Upvotes: 0
Views: 1161
Reputation: 2196
I would suggest using an S3 Lifecycle expiration rule, but if you have to do this in bash, try this:
BUCKET=""
aws s3api list-objects --bucket "$BUCKET" --query \
"Contents[?LastModified<=\`$(date -v-30d '+%Y-%m-%d')\`][].{object: Key}" \
| jq -r '.[].object' \
| xargs -I {} aws s3 rm s3://$BUCKET/{} --dryrun
Upvotes: 2