Last active
December 11, 2017 12:22
-
-
Save ilkka/3afe95116e70f1c7f39f2d85949b0ca8 to your computer and use it in GitHub Desktop.
PowerShell cmdlet for having Docker log in to ECR
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
# Install the AWS tools for PowerShell, then drop this in e.g. your profile file. | |
# As a bonus it exports `$Env:ECRHOST` which you can use when e.g. tagging or | |
# pushing images. | |
function Grant-ECRAccess { | |
[CmdletBinding()] | |
param ( | |
[parameter()] | |
[string] | |
$ProfileName = 'default', | |
[parameter()] | |
[string] | |
$Region = 'us-east-1' | |
) | |
$token = Get-ECRAuthorizationToken -Region $Region -ProfileName $ProfileName | |
$segments = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($token.AuthorizationToken)).Split(':') | |
$hostname = (New-Object System.Uri $token.ProxyEndpoint).DnsSafeHost | |
$Env:ECRHOST = $hostname | |
docker login -u ($segments[0]) -p ($segments[1]) $hostname | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment