Skip to content

Instantly share code, notes, and snippets.

@tsibley
Last active December 7, 2022 20:15
Show Gist options
  • Save tsibley/1bc47241534cf615ddfb11214dcb4534 to your computer and use it in GitHub Desktop.
Save tsibley/1bc47241534cf615ddfb11214dcb4534 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
group="${1:?usage: $(basename "$0") <group-name>}"
echo "# $group group"
echo
for role in owners editors viewers; do
echo "# $role"
aws cognito-idp list-users-in-group \
--user-pool-id us-east-1_Cg5rcTged \
--group-name ${group}/${role} \
--query 'Users[]' \
| jq --compact-output '.[]' \
| while read -r record; do
<<<"$record" yq --yaml-output --arg role "$role" '
def attr(name): .Attributes | map(select(.Name == name) | .Value) | .[0]?;
[{
role: $role,
name: attr("name"),
email: attr("email"),
username: .Username,
mustExist: true,
}]
'
echo
done
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment