Skip to content

Instantly share code, notes, and snippets.

@huevos-y-bacon
Last active October 3, 2024 11:18
Show Gist options
  • Save huevos-y-bacon/19480eaea236afa76e03fa9f61f8ac63 to your computer and use it in GitHub Desktop.
Save huevos-y-bacon/19480eaea236afa76e03fa9f61f8ac63 to your computer and use it in GitHub Desktop.
AWS Organizations - Get all custom SCPs and write to json
#!/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