Last active
October 3, 2024 11:18
-
-
Save huevos-y-bacon/19480eaea236afa76e03fa9f61f8ac63 to your computer and use it in GitHub Desktop.
AWS Organizations - Get all custom SCPs and write to json
This file contains 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
#!/usr/bin/env bash | |
# AWS Organizations - Get all custom SCPs and write to json | |
# shellcheck disable=2016 | |
pols=$(aws organizations list-policies \ | |
--filter SERVICE_CONTROL_POLICY \ | |
--query 'Policies[?AwsManaged==`false`].[Id,Name]' \ | |
--output text) | |
# shellcheck disable=2162 | |
xargs -n 2 <<< "$pols" | while read pol_id pol_name; do | |
out_name="${pol_name// /_}(${pol_id}).json" | |
echo "${out_name}" | |
aws organizations describe-policy \ | |
--policy-id ${pol_id} \ | |
--output json \ | |
--query 'Policy.[Content]' | jq -r '.[]' | jq \ | |
> ${out_name} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment