Skip to content

Instantly share code, notes, and snippets.

@Rovel
Created May 19, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rovel/659306b912f720746c2b216a5a23a124 to your computer and use it in GitHub Desktop.
Save Rovel/659306b912f720746c2b216a5a23a124 to your computer and use it in GitHub Desktop.
AWS List RDS SnapShots and check if they are public
#!/bin/bash
REGIONS=$(aws ec2 describe-regions --output json | awk -F'"' '/"RegionName":/ { print $4 }')
for Region in $REGIONS
do
Snaps=$(aws rds describe-db-snapshots --output json --region ${Region} | awk -F'"' '/"DBSnapshotIdentifier":/ {print $4 }')
if [ -z "$Snaps" ]; then
echo "No snapshots found in $Region"
echo "======================================================="
else
echo "Snapshots in ${Region}:"
echo
echo "$Snaps"
echo
for Snapshot in $Snaps
do
echo "${Snapshot}:"
CheckPub=$(aws rds describe-db-snapshot-attributes --db-snapshot-identifier $Snapshot --region ${Region} --output json --query 'DBSnapshotAttributesResult' | grep -B 5 "all" | awk -F '"' '/DBSnapshotIdentifier/ {print $4}')
if [ -z "$CheckPub" ]; then
echo "Not public."
echo
else
echo "This snapshot \"${CheckPub}\" is public!"
# aws rds describe-db-snapshots --db-snapshot-identifier $CheckPub --query 'DBSnapshots[*].DBSnapshotIdentifier'
echo
fi
done
echo "======================================================="
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment