Skip to content

Instantly share code, notes, and snippets.

@jkinkead
Created January 26, 2020 17:25
Show Gist options
  • Save jkinkead/94ddedcb18bdd31a380a5d730aa91e48 to your computer and use it in GitHub Desktop.
Save jkinkead/94ddedcb18bdd31a380a5d730aa91e48 to your computer and use it in GitHub Desktop.
ECR login helper for fish.
function ecr_login -d \
"ecr_login [profile_name] [region]: Log in to ECR via the AWS CLI." \
-a profile_name region
set -l args
if [ -n "$profile_name" ]
set args $args "--profile=$profile_name"
end
if [ -n "$region" ]
set args $args "--region=$region"
end
set -l auth_result (aws $args ecr get-authorization-token --output text)
if [ -z "$auth_result" ]
return
end
set -l token (echo "$auth_result" | cut -f2 | base64 --decode | cut -d: -f2)
set -l url (echo "$auth_result" | cut -f4)
echo "$token" | docker login --password-stdin -u AWS "$url"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment