Created
January 26, 2020 17:24
-
-
Save jkinkead/7a4eb001fa786009778fd31a8cb87035 to your computer and use it in GitHub Desktop.
ECR login helper for bash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Login to ECR, optionally specifying a profile namd and region. | |
ecr_login () { | |
local profile_name="$1" | |
local region="$2" | |
local args=() | |
if [ -n "$profile_name" ]; then | |
args=("${args[@]}" "--profile=$profile_name") | |
fi | |
if [ -n "$region" ]; then | |
args=("${args[@]}" "--region=$region") | |
fi | |
local auth_result=$(aws "${args[@]}" ecr get-authorization-token --output text) | |
if [ -z "$auth_result" ]; then | |
return | |
fi | |
local token=$(echo "$auth_result" | cut -f2 | base64 --decode | cut -d: -f2) | |
local url=$(echo "$auth_result" | cut -f4) | |
echo "$token" | docker login --password-stdin -u AWS "$url" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment