Skip to content

Instantly share code, notes, and snippets.

@qmcree
Last active July 19, 2018 20:00
Show Gist options
  • Save qmcree/bf71cc4d5b1b462857d972fa675cfbc8 to your computer and use it in GitHub Desktop.
Save qmcree/bf71cc4d5b1b462857d972fa675cfbc8 to your computer and use it in GitHub Desktop.
Authenticates to ECR without exposing password to other processes.
#!/bin/bash -e
AWS_ACCOUNT=
AWS_REGION=us-east-1
ECR_URL=https://${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
# On Mac, replace "base64 -d" with "base64 -D".
aws ecr get-authorization-token --query authorizationData[].authorizationToken --output text | base64 -d | cut -d: -f2 \
| docker login -u AWS --password-stdin ${ECR_URL} \
|| echo "Failed to authenticate to ECR." && exit 1
# Alternative
aws ecr get-login --no-include-email --region ${AWS_REGION} | awk '{printf $6}' \
| docker login -u AWS --password-stdin ${ECR_URL} \
|| echo "Failed to authenticate to ECR." && exit 1
@qmcree
Copy link
Author

qmcree commented Jul 19, 2018

See related aws/aws-cli#2875

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment