AWS CodeCommit

Setup git repository using AWS CodeCommit service

tl;dr

Git – an important tool in software developer’s job scope/daily life. One of the skill that employers will look for in candidate profile (at least in my country – Malaysia). Most of the software developer will store the source code in cloud services, such as GitHub, BitBucket, GitLab, self-hosted git repository or etc. AWS CodeCommit is one of the service where we can store our source code in AWS.

Let’s start

#1 Introduction to AWS CodeCommit

  • Belongs to “Always free” category
    • First 5 active users
    • 50GB storage per month
    • 10, 000 git requests per month
  • AWS CodeCommit pricing

#2 Setup your first repository in AWS CodeCommit

AWS CodeCommit

Navigate to CodeCommit from the AWS Console.

AWS CodeCommit repository dashboard

Click “Create repository”

Create repository in AWS CodeCcommit

Take note that Repository names are restricted to alphanumeric characters, plus ‘.’, ‘_’, and ‘-‘. No space allowed in repository name.

#3 Setup SSH connection to AWS CodeCommit

Steps to setup SSH connection in AWS CodeCommit

Generate public/private key pair from terminal. (Please use GitBash or Windows Subsystem Linux(WSL) for Windows platform)

AWS provided clear instructions regarding how to generate ssh key for:

$ ssh-keygen
For illustration purpose

By default, ssh private and public key will store as /home/username/.ssh/id_rsa and /home/username/.ssh/id_rsa.pub respectively. You may want to name it something else to prevent override your default.

$ cat ~/.ssh/id_rsa.pub
For illustration purpose

Copy the output, where you will need to paste it in AWS CodeCommit.

Upload SSH public key to CodeCommit Credentials. First, click the account at the top navigation bar and click the “My Security Credentials”.

Click My Security Credential

Navigate to AWS CodeCommit credentials tab.

AWS CodeCommit credentials

Upload SSH public key.

Copy and paste the generated ssh public key into the field

After uploaded SSH public key, AWS will generated a SSH Key ID which acts as git user to access AWS CodeCommit service. Copy the SSH Key ID.

Uploaded SSH public key

Now, modify the ssh config file /home/username/.ssh/config. If you don’t have the config file, feel free generate one using your favourite terminal editor (vi, nano or etc).

Host git-codecommit.*.amazonaws.com
  User Your-SSH-Key-ID
  IdentityFile /path/to/your/private key
For illustration purpose

#4 Testing SSH connection

$ ssh git-codecommit.ap-southeast-1.amazonaws.com

If all the setup is correct, we will get the success message in terminal as below.

For illustration purpose

#5 Git and AWS CodeCommit

Clone from AWS CodeCommit

$ git clone ssh://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/personal-website

Add AWS CodeCommit as remote

$ git remote add aws ssh://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/personal-website

Push to AWS CodeCommit

$ git push aws

or

$ git push origin

#6 View Repository in AWS CodeCommit

Source code push from local machine

Thanks for reading.  😁