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.
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.
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.
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.
This will generate two files:
2. Run the following command to display the value of the public key file (codecommit_rsa.pub):
Copy this value. It looks similar to the following:
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:
8. From the terminal, run the following command to change the permissions for the config file:
9. Run the following command to test your SSH configuration:
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:
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.
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.
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.
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.