Skip to content

Instantly share code, notes, and snippets.

@anujkaushal
Last active April 25, 2021 19:02
Show Gist options
  • Save anujkaushal/bfe6b70fd6d75281a56c9d6181534d1e to your computer and use it in GitHub Desktop.
Save anujkaushal/bfe6b70fd6d75281a56c9d6181534d1e to your computer and use it in GitHub Desktop.
tmpDir="/tmp"
randomName=`date +'%s'``php -r "echo rand();"`
awsUser="xxxxxxx"
awsAcID="xxxxxxxxxxxxx"
region="xx-xxxx-xx"
if [[ ! "$1" ]] ; then
echo "You must supply MFA."
exit 1
fi
echo "Get credentials"
aws sts get-session-token --serial-number arn:aws:iam::$awsAcID:mfa/$awsUser \
--token-code $1 --profile default | python -mjson.tool > $tmpDir/$randomName
echo "Get Access Key ID"
ACCESSKEY=`awk 'NR==3{print $2}' $tmpDir/$randomName | tr -d "\"" | sed s'/.$//'`
echo "Get Secret Access Key"
SECRETKEY=`awk 'NR==5{print $2}' $tmpDir/$randomName | tr -d "\"" | sed s'/.$//'`
echo "Get Session Token"
SESSIONTOKEN=`awk 'NR==6{print $2}' $tmpDir/$randomName | tr -d "\""`
echo "Docker login"
tmppassword=$(aws ecr get-login-password)
docker login --username AWS --password $tmppassword $awsAcID.dkr.ecr.$region.amazonaws.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment