· 6 years ago · Oct 27, 2019, 02:10 PM
1tmpDir="/tmp"
2randomName=`date +'%s'``php -r "echo rand();"`
3
4awsUser="xxxxxx"
5awsAcID="xxxxxxxxxxxx"
6
7if [[ ! "$1" ]] ; then
8 echo "You must supply MFA."
9 exit 1
10fi
11
12echo "Get credentials"
13aws sts get-session-token --serial-number arn:aws:iam::$awsAcID:mfa/$awsUser --token-code $1 --profile xxxxx | python -mjson.tool > $tmpDir/$randomName
14
15echo "Get Access Key ID"
16ACCESSKEY=`awk 'NR==3{print $2}' $tmpDir/$randomName | tr -d "\"" | sed s'/.$//'`
17
18echo "Get Secret Access Key"
19SECRETKEY=`awk 'NR==5{print $2}' $tmpDir/$randomName | tr -d "\"" | sed s'/.$//'`
20
21echo "Get Session Token"
22SESSIONTOKEN=`awk 'NR==6{print $2}' $tmpDir/$randomName | tr -d "\""`
23
24echo "Set Session Token: $SESSIONTOKEN"
25aws configure set aws_session_token $SESSIONTOKEN
26
27echo "Set Access Key ID: $ACCESSKEY"
28aws configure set aws_access_key_id $ACCESSKEY
29
30echo "Set Secret Key: $SECRETKEY"
31aws configure set aws_secret_access_key $SECRETKEY
32
33echo "Docker login"
34$(aws ecr get-login --no-include-email)