juanesech
5/8/2018 - 4:40 PM

Create AWS Cognito Users

Bash create cognito users based on text list

#!/bin/bash
users=$(cat users.txt)
poolId=$1
AWS_DEFAULT_REGION=$2
AWS_ACCESS_KEY_ID=$3
AWS_SECRET_ACCESS_KEY=$4

#Parameters validation
if [[ $2 && $3 && $4 ]]; then
  export AWS_DEFAULT_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
  else
    echo "WARN: The AWS variables did not provided, using system settings"
fi

#Create Users
for i in $users; do
  userExists=$(aws cognito-idp list-users --user-pool-id $UserPoolId --query "Users[?Username == '$i'].Username" --output text)
  if [[ userExists ]]; then
    echo "User $i already exists"
  else
    aws cognito-idp admin-create-user \
     --user-pool-id $poolId \
     --username $i \
     --temporary-password "password"
 fi
done