aws-cli allows you to interact with AWS from your command line. First thing you have to do is login. But if you have multiple AWS accounts you want to make sure you are signing into the right one. You should have two files in your
.aws directory in your home folder. You should have
credentials should look something like this.
[default] aws_access_key_id = C7E... aws_secret_access_key = YTgn....
But if you have multiple accounts then it should look more like this.
[default] aws_access_key_id = C7E... aws_secret_access_key = YTgn.... [account1] aws_access_key_id = 4FD... aws_secret_access_key = 02e.... [account2] aws_access_key_id = 5E8... aws_secret_access_key = ab0c....
~/.aws/config file is generated with
aws configure and should look something like this.
[default] region = us-east-1 output = json [account1] region = us-east-1 output = json [account2] region = us-east-2 output = json
So now when you login to aws you can specify a profile.
$(aws ecr get-login --no-include-email --region us-east-1 --profile account2)
You'd think if your region was in your config you wouldn't need it. This wasn't the case for me. Also
--no-include-email seems to be necessary as well, although on a server once, I was able to simply use
$(aws ecr get-login) and it worked. See the image below on what worked for me and what didn't.