How To Build a Full Stack Web App Using AWS Amplify | Part 2 - Setting Up Project Repository In CodeCommit

July 7, 2020

How To Build a Full Stack Web App Using AWS Amplify | Part 2 - Setting Up Project Repository In CodeCommit

Last week we tackled the installation and integration of AWS Amplify in Part 1 of this 3 part blog series. This week, we’ll have a look at AWS CodeCommit and walk you through local content migration, Git installation and creating the CodeCommit repository. Building your own web app may seem like a daunting task, especially given all the steps you have to follow before the actual coding has even begun, but to quote the great Stephen Keague, “Proper planning and preparation prevents poor performance”. So make yourself a cup of java, put on your dev pants, and let’s jump into part 2.

Setup required access to AWS CodeCommit

Before you can migrate local content to CodeCommit, you must create and configure an IAM user for CodeCommit and configure your local computer for access.

Create an IAM user

Every user that needs access to your code needs to have a CodeCommit account. This user account is used to communicate with CodeCommit and keep track of who is making changes to the project. 

1. Open the IAM console


2. Choose “Users” and then select the “Add User” option to create the CodeCommit user.


3. Fill in the user name and select Programmatic access under the Access Type. Click “next” after completing these steps to move on to Permissions. 

4. Select Attach Existing Policies and search for CodeCommit. Select the AWSCodeCommitPowerUser and click Next: Tags.

5. Click Next Review on the Tags page.

6. Review the user details and click Create User.

7. On the resulting page click on Download .csv. This file contains the credentials for the user and should be stored in a safe place. 


Set up SSH access to CodeCommit

1. From the terminal on your local machine, run the ssh-keygen command, and follow the directions to save the file to the .ssh directory for your profile.

$ ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user-name/.ssh/id_rsa):
Type /home/your-user-name/.ssh/scribe-codecommit-rsa

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

Your identification has been saved in /home/user-name/.ssh/codecommit_rsa.
Your public key has been saved in /home/user-name/.ssh/codecommit_rsa.pub.
The key fingerprint is:
45:63:d5:99:0e:99:73:50:5e:d4:b3:2d:86:4a:2c:14 user-name@client-name
The key's randomart image is:
+--[ RSA 2048]----+
|        E.+.o*.++|
|        .o .=.=o.|
|       . ..  *. +|
|        ..o . +..|
|        So . . . |
|          .      |
|                 |
|                 |
|                 |
+-----------------+

This will generate two files:

  • The codecommit_rsa file, which is the private key file.
  • The codecommit_rsa.pub file, which is the public key file.

2. Run the following command to display the value of the public key file (codecommit_rsa.pub):

cat ~/.ssh/codecommit_rsa.pub

Copy this value. It looks similar to the following:

ssh-rsa EXAMPLE-AfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMCVVMxCzAJB
gNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb2
5zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhc
NMTEwNDI1MjA0NTIxWhcNMTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAw
DgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDAS=EXAMPLE user-name@ip-192-0-2-137

3. Sign in Sign in to the AWS Management Console and open the IAM console.

4. In the IAM console, in the navigation pane, choose Users, and from the list of users, choose the IAM user you created above. On the user details page, choose the Security Credentials tab, and then choose Upload SSH public key.


5. Paste the contents of your SSH public key into the field, and then choose Upload SSH public key.

6. Copy or save the information in SSH Key ID.

7. On your local machine, use a text editor to create a config file in the ~/.ssh directory, and then add the following lines to the file, where the value for User is the SSH key ID you copied earlier:

Host git-codecommit.*.amazonaws.com
	User APKAWXSL3PJ7H3H3CMU6
	IdentityFile ~/.ssh/scribe-codecommit-rsa

8. From the terminal, run the following command to change the permissions for the config file:

chmod 600 config

9. Run the following command to test your SSH configuration:

ssh git-codecommit.us-east-2.amazonaws.com


You will be asked to confirm the connection because git-codecommit.us-east-2.amazonaws.com is not yet included in your known hosts file. The CodeCommit server fingerprint is displayed as part of the verification (a9:6d:03:ed:08:42:21:be:06:e1:e0:2a:d1:75:31:5e for MD5 or 3lBlW2g5xn/NA2Ck6dyeJIrQOWvn7n8UEs56fG6ZIzQ for SHA256).


After you have confirmed the connection, you should see confirmation that you have added the server to your known hosts file and a successful connection message. If you do not see a success message, check that you saved the config file in the ~/.ssh directory of the IAM user you configured for access to CodeCommit, and that you specified the correct private key file.


For information to help you troubleshoot problems, run the ssh command with the -v parameter:

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

Install Git

Git needs to be installed locally in order to communicate with CodeCommit and to keep our code organised. To work with files, commits, and other information in CodeCommit repositories, you must install Git on your local machine. CodeCommit supports Git versions 1.7.9 and later, but we recommend using a recent version of Git. In order to install Git, navigate to the Git Downloads page and install Git for your operating system.

Create CodeCommit repository

In this section, utilise the CodeCommit console to create the CodeCommit repository you will use for the rest of this tutorial.

1. Open the CodeCommit console

2. In the region selector, choose the AWS Region where you want to create the repository.  

3. Navigate to the Repositories page, click on Create repository and fill out the Name, Description and optional Tags.

4. Choose Create.

Now that you have your repository created, let’s move on to connecting our Git installation to CodeCommit.

Connect to CodeCommit and Clone the repository

1. Login to your AWS account and open the CodeCommit console.

2. Make sure you’re in the correct region where the repository was created, and choose the repository you are looking from from the list.

4. We’re going to be using SSH to communicate with CodeCommit, so select the SSH tab. Since we’ve already set up the SSH credentials above, we just need to copy the repository clone command to clone the repository.

5. In the terminal paste the command to clone the repository.

git clone ssh://git-codecommit.eu-west-1.amazonaws.com/v1/repos/amplify-scribe

At this point we’ll have an empty repository which we can start working with.

After completing the steps outlined above, your code repository should be set up and we can start building our web application. In the third and final blog post, we will work step by step through the AWS Amplify project initialisation and setting up the dev environment, so be sure to keep an eye on our site and social media pages. If you’re struggling with some of the steps or have any questions, please feel free to reach out. 

Jacques Fourie

Dirk Coetzer

Senior Engineer

Swipe iX Newsletter

Subscribe to our email newsletter for useful tips and valuable resources, sent out monthly.