If you don't already know AWS has it's very own code repository service called CodeCommit.  In today's tutorial, you can follow along with me as I setup a repository using CodeCommit.

Configure your AWS account

To begin I'll configure my AWS account appropriately and allow git to connect to CodeCommit using SSH.

  1. Create an SSH keypair.
ssh-keygen -t rsa -b 4096

2. Fill in the details such as the keyname and passphrase when prompted. My key's name will be codecommit_rsa.

Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\user01/.ssh/id_rsa): C:\Users\user01/.ssh/codecommit_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in test.
Your public key has been saved in test.pub.
The key fingerprint is:
SHA256:vdbdfgshsdf1231sdfdsfg546y34
The key's randomart image is:
+---[RSA 4096]----+
|                 |
|                 |
+----[SHA256]-----+

3. Navigate to the AWS console, go to IAM and click on your username. Go to the Security credentials tab and under "SSH keys for AWS CodeCommit" click on the Upload SSH public key button. Paste in your the contents of the public key in the box that pops up.

Copy the SSH key ID that is generated to a safe location. You will need in the next step.

4. Head back to your terminal and navigate to the directory that contains your CodeCommit private and public keys. Mine is located in C:\Users\user01/.ssh/.

In this directory create a file with the name config, make sure not to give it an extension.

Open the file and paste in the following, replace <YOUR_SSH_KEY_ID> with the SSH key ID you saved in the previous step.

Host git-codecommit.*.amazonaws.com
  User <YOUR_SSH_KEY_ID>
  IdentityFile ~/.ssh/codecommit_rsa

Test SSH Settings with CodeCommit

  1. Now it's time to test CodeCommit's SSH access. Execute the following:
ssh git-codecommit.us-east-2.amazonaws.com

You should see the following output.

The authenticity of host 'git-codecommit.us-east-2.amazonaws.com (52.95.20.253)' can't be established.
RSA key fingerprint is SHA256:SAsdD12df73yOP23423Q.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git-codecommit.us-east-2.amazonaws.com,52.95.20.253' (RSA) to the list of known hosts.
Enter passphrase for key 'C:\Users\test01/.ssh/codecommit':
You have successfully authenticated over SSH. You can use Git to interact with AWS CodeCommit. Interactive shells are not supported.Connection to git-codecommit.us-east-2.amazonaws.com closed by remote host.
Connection to git-codecommit.us-east-2.amazonaws.com closed.

Cool, if you got this far then you have successfully configured CodeCommit to use SSH.

Create a Repository

  1. Time to create a repository! Navigate to the CodeCommit service. Fill in the repo name and description.

2. Once your empty repo is created, click open the Clone URL drop down and select Clone SSH. This will copy the SSH link for git.

3. Head back into your terminal and clone the repo.

git clone ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/test-repo-01

If you've configured everything correct you should have been able to pull down an empty repo.

Now you can create the files you want and use git to track changes!

Bonus

Here is a CLI friendly command using the awscli.

aws codecommit create-repository \
    --repository-name REPO-01 \
    --repository-description "Test repo" \
    --tags env=test \
    --region us-east-2