Created
August 10, 2017 19:34
-
-
Save sathed/bc2fd35d0982186c4c773a715fc5d703 to your computer and use it in GitHub Desktop.
AWS Search IAM Policies for Specific Action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Get the ARNs of the policies and store in the policies_arn array. | |
| mapfile -t policies_arn < <(aws iam list-policies --query 'Policies[*].[Arn]' --output text) | |
| # Get the VersionIds for each policy and store in the policies_ver array. | |
| mapfile -t policies_ver < <(aws iam list-policies --query 'Policies[*].[DefaultVersionId]' --output text) | |
| # Use a for loop to loop through each policy and store the policy document in ~/policies.txt | |
| for (( i=0; i<${#policies_arn[@]}; i++ )); do echo ${policies_arn[i]} >> policies.txt && aws iam get-policy-version --policy-arn ${policies_arn[i]} --version-id ${policies_ver[i]} --output json >> ~/policies.txt; done | |
| # Open up policies.txt in a text editor and search for your action. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment