Getting Started with AWS CodeCommit

As discussed earlier, AWS CodeCommit is a secure and highly scalable source control service which allows you to create multiple private Git repositories without having to bother about any of the underlying management overheads. You can use it to store anything, from code, to application binaries, to even code packages, all using the standard Git-like functionality. This makes CodeCommit extremely easy to work with even if you have not used it before. Here is the gist of some of the most commonly used Git commands and how you can leverage them with CodeCommit:

  • git clone: Used to clone and connect the AWS CodeCommit repository over to your local development server.
  • git add: Once the repository is cloned locally, you can use it to add, edit, or delete files as you see fit. Once done, use the git add command to stage the modifications in your local Git repository.
  • git commit: Used to commit the modifications made to the files to the local Git repository.
  • git push: Used to push the committed files and changes over to the AWS CodeCommit repository.
  • git pull: Used to ensure that the files you are working on are synced and are of the latest version from the AWS CodeCommit repository.

In this section, we will be looking at a few simple steps to enable you to create your very own source code repository using the AWS Management Console. However, before we move on to that, it is important to understand some of the different connections that you can use to connect to your CodeCommit repository. This can vary based on your development environments as well as security requirements:

  • Using the HTTPS connections: Configuring Git credentials using HTTPS connections is by far the simplest and most widely used method for connecting to your Git repository. With this set up, you simply generate a static username and password using AWS IAM. Once the credentials are created, you can then use them with Git and any third-party tool, such as an IDE, for authentication.
  • Using the SSH connections: In this case, a user will be required to create public and private key files on your local development server that Git and AWS CodeCommit can use for SSH authentication. The public key generated in this process gets associated with your IAM user, whereas the private key remains on the local development server. The generation of the keys varies from operating system to operating system and can be a tedious process at times to manage.

For this section, however, we will be leveraging the SSH connections method itself for connecting to our AWS CodeCommit repository:

  1. To get started, first log in to your AWS Management Console and filter the IAM service using the Filter option provided. Alternatively, you can also select URL https://console.aws.amazon.com/iam/ to view the IAM dashboard.
  2. Here, we will start off by creating a dedicated user that will have full management rights to our CodeCommit repository. Select the Users option from the IAM dashboard's navigation pane to bring up the list of currently created IAM users.
  3. Next, select the Add user option. This will bring up the Add user page where you can provide a suitable User name as well as opt for the user's Access type. In this case, the CodeCommit user will only require Programmatic access. Click Next to proceed.
  4. Moving on, in the Permissions page, we are required to filter and attach the AWSCodeCommitFullAccess policy to our newly created user. To do so, select the Attach existing policies directly option and select the AWSCodeCommitFullAccess policy, as shown in the following screenshot. Alternatively, you can also provide a customized access policy here based on your requirements:
  1. Complete the user creation process by reviewing the changes and making a note of the user's new access and secret keys as well.

At this point, with your CodeCommit IAM user created, we now move on to the next part of this section where we create and configure a set of public and private keys for the IAM user, using a simple Linux-based development server. Follow URL http://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-windows.html if you are using a Windows operating system as your development server:

  1. Log in to your development server and run the following command to generate the new set of keys:
# ssh-keygen 
  1. When prompted, save the keys in the following directory structure:
/home/<USER_NAME>/.ssh/<KEY_NAME> 

Make a note of the public and private keys' locations, as depicted in the following screenshot:

  1. Next, display and copy the public key's contents, using the following command. Note the public key will be saved in the file with a .pub extension:
# cat /home/<USER_NAME>/.ssh/<KEY_NAME> 
  1. Log in to your IAM dashboard once again and select the newly created user from the Users page. Select the user's Security Credentials tab. Here, under the SSH keys for AWS CodeCommit section, click on Upload SSH public key to paste the entire copied text from the earlier step.
  1. Once completed, you should now see a unique key auto-generated under the SSH key ID column, as shown in the following screenshot. Copy this SSH key ID as we will be requiring it in the next steps:
  1. With the public key uploaded to IAM and the new SSH key ID generated, the final step is to create a simple config file in your local development server with the following contents pasted into it:
# vi ~/.ssh/config
##### SUBSTITUTE THE <VALUES> WITH YOUR ACTUAL ONES #####

Host git-codecommit.*.amazonaws.com User <SSH_KEY_ID> IdentityFile ~/.ssh/<PRIVATE_KEY_FILENAME>
  1. Save the file once done. Remember to modify the permissions of your config file before moving on to the verification step:
# chmod 600 config
  1. To verify the connectivity, simply use the following command to SSH to the AWS CodeCommit endpoint. Since this will be a first connect, you will be prompted to verify the connection for authenticity. Type in yes when prompted:
# ssh git-codecommit.us-east-1.amazonaws.com
The endpoint you use will be specific to the AWS region that you operate out of. You can view the list of region-specific CodeCommit URLs along with the availability of the CodeCommit service at http://docs.aws.amazon.com/codecommit/latest/userguide/regions.html.

With this step, we have successfully validated and connected our development server with the AWS CodeCommit service! But where is our CodeCommit repository?

  1. To create the repository, log in to the AWS CodeCommit service using URL https://console.aws.amazon.com/codecommit. Remember to change the Region based on what you selected during the key verification state.
  2. Since this is our first time working with CodeCommit, select the Get Started option to begin with. This will display the Create repository page, as shown in the following screenshot:
  1. Provide a suitable Repository name and an optional Description. Click on Create repository once done.
  2. You can additionally configure notifications for specific Event types, such as pull requests and commits made to your repo in the Configure email notifications page. Simply select an existing SNS topic or opt to Create a new topic based on your requirements. Once done, click on Save to complete the repository creation process.

With the repository created, you can now use the development server and connect to it using a simple git clone command. You can obtain your repository's connection URL anytime by simply selecting the Connect option present on the Code page:

# git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/<YOUR_CODECOMMIT_REPO> 

Here's a snapshot of the first git clone command output:

Since the repository is empty, the cloning process simply creates a folder with your repository's name on your development server. You can now use this folder as a code source control by simply adding your program files, binaries, and other application-specific data to it.

In the next section, we will be using this repository as our WordPress application source control and explore a few simple commands and features that are provided as a part of AWS CodeCommit.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset