Skip to content

Instantly share code, notes, and snippets.

@bsingr
Created July 28, 2023 07:15
Show Gist options
  • Save bsingr/1e2f3f3af4473a227fe85df0121a457c to your computer and use it in GitHub Desktop.
Save bsingr/1e2f3f3af4473a227fe85df0121a457c to your computer and use it in GitHub Desktop.
aws_s3_last_modified_buckets
#!/bin/bash
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=
buckets_wsv=$(aws s3api list-buckets --query "Buckets[].Name" --output text)
echo $buckets_wsv
echo
echo "---"
echo
buckets=($buckets_wsv)
echo "bucket,last_modified_object,last_modified_object_updated_at,last_modified_object_size"
for bucket in "${buckets[@]}"
do
echo -n "$bucket,"
last_modified=$(aws s3api list-objects-v2 --bucket $bucket | jq -r '.[] | max_by(.LastModified) | [.Key, .LastModified, .Size] | @csv')
echo $last_modified
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment