Skip to content

Instantly share code, notes, and snippets.

@duboisf
Created February 3, 2025 17:15
Show Gist options
  • Save duboisf/3889c6b7b60d100791467bebbb99a917 to your computer and use it in GitHub Desktop.
Save duboisf/3889c6b7b60d100791467bebbb99a917 to your computer and use it in GitHub Desktop.
Get all s3 bucket policies in an aws account using nushell

Get all s3 bucket policies in an aws account using nushell

In parallel! Saves output to a file so you can simply do open /tmp/bucket-policies.nuon after:

^aws s3api list-buckets
| from json
| get Buckets.Name
| par-each { |bucket|
    let policy = try {
        ^aws s3api get-bucket-policy --bucket $bucket err> /dev/null
        | from json
        | get Policy
        | from json
        | to json
    } catch {
        "N/A"
    }
    {
        bucket: $bucket,
        policy: $policy
    }
}
| where policy != N/A
| save /tmp/bucket-policies.nuon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment