Skip to content

Instantly share code, notes, and snippets.

@ilkka
Last active December 11, 2017 12:22
Show Gist options
  • Save ilkka/3afe95116e70f1c7f39f2d85949b0ca8 to your computer and use it in GitHub Desktop.
Save ilkka/3afe95116e70f1c7f39f2d85949b0ca8 to your computer and use it in GitHub Desktop.
PowerShell cmdlet for having Docker log in to ECR
# 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