-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.sh
executable file
·98 lines (90 loc) · 2.32 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Initialize variables for optional parameters
AWS_PROFILE=""
AWS_REGION=""
# Initialize variables for required parameters with empty defaults
USER_POOL_ID=""
EMAIL=""
GIVEN_NAME=""
FAMILY_NAME=""
PASSWORD=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--user-pool-id)
USER_POOL_ID="$2"
shift # past argument
shift # past value
;;
--email)
EMAIL="$2"
shift # past argument
shift # past value
;;
--given-name)
GIVEN_NAME="$2"
shift # past argument
shift # past value
;;
--family-name)
FAMILY_NAME="$2"
shift # past argument
shift # past value
;;
--password)
PASSWORD="$2"
shift # past argument
shift # past value
;;
--profile)
AWS_PROFILE="--profile $2"
shift # past argument
shift # past value
;;
--region)
AWS_REGION="--region $2"
shift # past argument
shift # past value
;;
*)
shift # past argument
;;
esac
done
# Check for required parameters
if [[ -z "$USER_POOL_ID" || -z "$EMAIL" || -z "$GIVEN_NAME" || -z "$FAMILY_NAME" || -z "$PASSWORD" ]]; then
echo "Error: Missing required parameters."
echo "Usage: $0 --user-pool-id <value> --email <value> --given-name <value> --family-name <value> --password <value> [--profile <name>] [--region <value>]"
exit 1
fi
# AWS Cognito command to create a new user in the user pool
# shellcheck disable=SC2086
aws cognito-idp admin-create-user \
--user-pool-id "$USER_POOL_ID" \
--username "$EMAIL" \
--user-attributes \
Name=email,Value="$EMAIL" \
Name=email_verified,Value=true \
Name=given_name,Value="$GIVEN_NAME" \
Name=family_name,Value="$FAMILY_NAME" \
--message-action SUPPRESS \
$AWS_PROFILE $AWS_REGION > /dev/null
# Check if the previous command was successful
if [ $? -eq 0 ]; then
echo "User created successfully."
# AWS Cognito command to set a new user's password
# shellcheck disable=SC2086
aws cognito-idp admin-set-user-password \
--user-pool-id "$USER_POOL_ID" \
--username "$EMAIL" \
--password "$PASSWORD" \
--permanent \
$AWS_PROFILE $AWS_REGION > /dev/null
if [ $? -eq 0 ]; then
echo "Password set successfully."
else
echo "Failed to set password."
fi
else
echo "Failed to create user."
fi