-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-auth2.sh
executable file
·48 lines (42 loc) · 1.08 KB
/
aws-auth2.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
#!/bin/bash
usage () {
echo "
Usage: $0 options
options:
-m arn of your virtual mfa device
-t token generated by your mfa device
"
exit
}
while getopts "m:t:" OPTION
do
case $OPTION in
m)
mfa_serial_number=$OPTARG
;;
t)
token_code=$OPTARG
;;
*)
usage;
exit 1
;;
esac
done
if [ ! "$mfa_serial_number" ] || [ ! "$token_code" ]
then
usage
exit 1
else
output=($(aws sts get-session-token --duration 129600 --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' --output text --serial-number $mfa_serial_number --token-code $token_code))
AWS_ACCESS_KEY_ID="${output[0]}"
AWS_SECRET_ACCESS_KEY="${output[1]}"
AWS_SESSION_TOKEN="${output[2]}"
aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID"
aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
aws configure set aws_session_token "$AWS_SESSION_TOKEN"
echo "token_code: $token_code"
echo "AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID"
echo "AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY"
echo "AWS_SESSION_TOKEN: $AWS_SESSION_TOKEN"
fi