A couple of days ago the team received a request from one of the engineering teams about monitoring on an S3 bucket. As part of an application upgrade they were pointing the application at a new bucket and they wanted to make sure that there were no more files posted to the old bucket. While we did not have anything configured to track files that are written to the bucket. I could setup CloudTrail to watch the bucket and log any changes to it, but I figured it would just be easier to give them a CLI command that they could run to check it:
aws s3api list-objects-v2 \
--bucket ${BUCKET} \
--query "sort_by(Contents,&LastModified)[*].[Key, LastModified]" \
--output text | head -1
This will go through the named bucket and sort it by the last modified date and then print out the last modified date. It takes a little while to do on our bucket since it had a couple hundred thousand items in it, but it gets the job done.
Comments