Created
November 28, 2021 02:38
-
-
Save jsleeio/6ccafb5e2c82a264de03d754864d5b36 to your computer and use it in GitHub Desktop.
automatic Docker login to ECR via AWS configuration data
This file contains 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
docker-login-ecr() { | |
local ecr_account_profile=${ECR_ACCOUNT_PROFILE:-utility} | |
local ecr_region | |
local ecr_account_id | |
ecr_account_id="$(aws configure get "$ecr_account_profile.role_arn" | awk -F: '{ print $5 }')" | |
if [[ -z "$ecr_account_id" ]] ; then | |
return 1 | |
fi | |
ecr_region=$(aws configure get "$ecr_account_profile.region") | |
if [[ -z "$ecr_region" ]] ; then | |
return 1 | |
fi | |
aws ecr get-login-password \ | |
--profile="$ecr_account_profile" \ | |
--region="$ecr_region" \ | |
| docker login \ | |
--username=AWS \ | |
--password-stdin \ | |
"${ecr_account_id}.dkr.ecr.${ecr_region}.amazonaws.com" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment