Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config AWS CodeCommit config file for an specific repo

Im having the following issue. As part of my job, I handle multiple AWS Accounts, each of which have a separate AWS CodeCommit repos and account-specific IAM Users (which result on different User IDs)

I want to find a way that I can config my ssh to access different accounts depending on the repo

Currently it works correctly, as my config file looks like this:

  Host git-codecommit.*.amazonaws.com
     User APKAEIBAERJR2EXAMPLE
     IdentityFile ~/.ssh/codecommit_rsa

What I need, is to be able to add different repos that use different accounts so that I don't have to edit the config file everytime I switch from one project to another i.e.

#Use this User ID and ssh-key for repo A
Host git-codecommit.*.amazonaws.com 
  User IAMUSERIDFROMACCOUNT1
  IdentityFile ~/.ssh/codecommit_rsa

#Use this User ID and ssh-key for repo B
Host git-codecommit.*.amazonaws.com
  User IAMUSERFROMANOTHERAWSACCOUNT
  IdentityFile ~/.ssh/codecommit_rsa

I have browsed everywhere without finding the right answer. Thanks in advance for any help on this topic.

Regards

like image 885
Pablo Adoue Avatar asked May 31 '16 02:05

Pablo Adoue


People also ask

How do I change my repository name on CodeCommit?

To change a CodeCommit repository's nameRun the update-repository-name command, specifying: The current name of the CodeCommit repository (with the --old-name option). To get the CodeCommit repository's name, run the list-repositories command. The new name of the CodeCommit repository (with the --new-name option).

Which two methods are used to authenticate to a CodeCommit repository?

Git credentials, an IAM-generated user name and password pair you can use to communicate with CodeCommit repositories over HTTPS. SSH keys, a locally generated public-private key pair that you can associate with your IAM user to communicate with CodeCommit repositories over SSH.


2 Answers

You are on the right track :-). You need to modify your config file and make a Host entry for each User/IdentityFile pair. For example:

Host git-account1 
  User IAMUSERIDFROMACCOUNT1 
  IdentityFile ~/.ssh/codecommit
  HostName git-codecommit.us-east-1.amazonaws.com
Host git-account2 
  User IAMUSERIDFROMACCOUNT2
  IdentityFile ~/.ssh/codecommit
  HostName git-codecommit.us-east-1.amazonaws.com
Host git-account3 
  User IAMUSERIDFROMACCOUNT3
  IdentityFile ~/.ssh/codecommit
  HostName git-codecommit.us-east-1.amazonaws.com

Your git command lines would look like this:

git clone ssh://git-account1/v1/repos/AccountOneRepo

git clone ssh://git-account2/v1/repos/AccountTwoRepo

git clone ssh://git-account3/v1/repos/AccountThreeRepo

like image 147
Wade Matveyenko Avatar answered Nov 15 '22 02:11

Wade Matveyenko


This worked for me.

You need to change SSH Key ID. SSH Kye ID you can get from IAM Users -> select_user -> security_credentials-> SSH Key ID

file name ~/.ssh/config

Host git-codecommit.ap-south-1.amazonaws.com 
  User <SSH Key ID> 
  IdentityFile ~/.ssh/id_rsa
  HostName git-codecommit.ap-south-1.amazonaws.com
Host git-codecommit.us-east-2.amazonaws.com 
  User <SSH Key ID> 
  IdentityFile ~/.ssh/id_rsa
  HostName git-codecommit.us-east-2.amazonaws.com
like image 29
Viraj Wadate Avatar answered Nov 15 '22 02:11

Viraj Wadate