Wednesday, December 18, 2019

Using CodeCommit with RStudio on Windows

Just some notes that were helpful as I'm a newbie to Git...

Assuming you're not the one responsible for granting access to AWS CodeCommit in your organization and you receive three pieces of information, something like this:

1) ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/project_name

2) user: ABC123

3) Private Key (see below)

The following article will be helpful:


After installing Git consider installing software like Tortoise Git for convenience. You might also want to install an SSH client like PuTTY.

As part of the AWS instructions, you'll need to edit the config file in the c:\users\<username>\.ssh folder:

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

and in the same folder, the codecommit_rsa file should contain the RSA key provided similar to the one below. Note that you might have to remove extra lines that are inserted as you copy and paste this RSA key (maybe Windows \r\n vs. Unix \n?) In general, editing anything between BEGIN and END lines is a bad idea, but removing blank lines did work for me.


-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCbyj6eG64iuNCiOutpniir6APKOCX53pXWIq45NQuQU9j7rV9/
Pa7tm8bHUNaQZe1SJqH81SmLlKZwApv3tFfcnF7HDWsgDKMhxuMfw8pTcb1HDSUm
Pt5mGY5iTl9MLC4nZpVpj4FBa+OkPUKxn8GzozNyo2NJ/uhxCgrTJw+VEQIDAQAB
AoGBAIWfjt3mOBIoGytLBihtM81fEAEe79PGCxbEYFNJIEYG5RHZvxNQQP4kovbK
a38nLctMv5ww6ZWDRs7ELirkUIbcGjlinKxVJF9gl8i/Wm4nr1C4Ab1XK6l8UU+J
T09OuJTkaNuZvawlHrAO/Jn4zo1KL5H4aky8Hc6ZRRT2FngBAkEA3w0EI3njNr08
5iJUsXXNf1T31jDig46KhrALGU0YazT6NpjF07mcLELllNYheUEKSOf9t1gF5hqI
20NM9xqWcQJBALLNqjnw4MvW05FQTHgXuiDV06Kj8NdhH8un1jiE8liu1fFi2o3Z
ge6IQY5MWfxPaX/ojqmR4e8c4ebzwzLyeKECQAKGfTOBn8bw4Y2heeAAe3EjnyK3
rvjaVkssFxQUQWCFWwffNu4svc3qe/rxabObvugQaFj5ECgIyN/ipS5vCKECQG4o
6dyivEy5wUVA/Kvsql76flYwvPxlOUqm0AOoXQsoRGVgqxhDzppgVktOXQ5m+q+0
Xti4KUPBPqikvDmSS6ECQQCAT0o2tjTLXHGFImRImbq/NESP4cHEosdV0EsmTGv3
w8u99TkuQAOBfMG7lucaTUCFozeijvc7pQXU6eyUo3DJ
-----END RSA PRIVATE KEY-----

The AWS article documents a couple of SSH commands you can run in the Windows CMD shell (ah, memories of MS-DOS). PowerShell presumably would work as well. The -v is for verbose and is handy if you're having problems. When it works you will be happy.

ssh -v git-codecommit.us-west-2.amazonaws.com

Note that I never had to account for the public key in the public-key cryptography scheme. Presumably, as a public key, it is handled when connecting to AWS and was setup by the administrator that sent you the private key. Comments welcome!

If you're using RStudio, there is already support for Git built-in. I would suggest experimenting with RStudio using a local Git repository and then when you're ready to place files in CodeCommit, clone the empty folder as the AWS article suggests and copy in files to place them under version control.

git clone ssh://ABC123@git-codecommit.us-west-2.amazonaws.com/v1/repos/project_name local_proj_folder

The Git tools will recognize the .git folder and you'll be off to the races. There seems to be a whole subculture around Git so happy searching!