Configure and Work with CodeCommit from the CLI

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we go through the process of configuring a CodeCommit repository from the AWS Command Line Interface. We also go through some key prerequisite steps, such as installing Git, configuring HTTPS credentials, and preparing the environment to work with Git and CodeCommit. This lab covers the steps that need to be taken anytime you work with CodeCommit from the CLI.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Server from an Amazon Linux 2 AMI
  1. Navigate to EC2.
  2. Click Launch Instance.
  3. Select the Amazon Linux 2 AMI (HVM), SSD Volume Type 64bit (x86) AMI.
  4. Select t2.micro as the instance type.
  5. Select the VPC provided in the lab.
  6. Select the subnet provided.
  7. Select Enable for Auto-assign Public IP.
  8. Click Review and Launch > Launch.
  9. Select Create a new key pair.
  10. Enter "confighttps" as the key pair name.
  11. Click Download Key Pair.
  12. Click Launch Instances > View Instances.
Install Git and Create IAM CodeCommit Credentials
  1. Select the newly created instance.

  2. Click Connect at the top of the screen.

  3. Open a terminal window and navigate to the folder for your downloads.

  4. Linux/Mac users: Execute the following command:

    chmod 400 confighttps.pem
  5. Linux/Mac users: Run the example SSH command from the Connect window in the AWS Management Console in your terminal application.

    Note: If you are using Windows/PuTTY, use the link in the Connect window in the AWS Management Console that says connect using PuTTY and follow the instructions.

  6. In the terminal, run the following command:

    sudo yum update -y

    *Note: We were just describing the IAM steps, but the needed permissions already exist for the cloud_user.

  7. In the AWS Management Console, navigate to IAM > Users.

  8. Click on cloud_user.

  9. Click Add permissions > Attach existing policies directly.

  10. Type "AWSCodeCommit" in the filter search box.

  11. Select the AWSCodeCommitFullAccess policy.

  12. Click Cancel. (We are clicking cancel here because the cloud_user already has the needed permissions and the lab’s cloud_user account can not be modified).

  13. In the terminal, run the following command to install Git:

    sudo yum install git -y
  14. In the AWS Management Console, with cloud_user opened, click the Security credentials tab.

  15. Click Create access key.

  16. Click Download .csv file.

  17. Navigate to the bottom of the screen, and click Generate under HTTPS Git credentials for AWS CodeCommit.

  18. Click Download credentials > Close.

Create CodeCommit Repository
  1. Open the terminal window.

  2. Configure the AWS CLI credentials:

    aws configure
  3. Enter the AWS Access Key and Secret Access Key for the cloud_user user.

  4. Enter us-east-1 as the region and accept the Default output format.

  5. Run the following command to create a CodeCommit repository from the AWS CLI:

    aws codecommit create-repository --repository-name RepoFromCLI --repository-description "My demonstration repository"
  6. In the AWS Management Console, open CodeCommit and refresh the screen.

  7. Click on the RepoFromCLI repository link to open it.

  8. Click Add file > Upload file.

  9. Click Choose file.

  10. Select any small file from your machine you don’t mind uploading.

  11. Enter your name as the author name and your email as the email address.

  12. Click Commit changes.

  13. Return to your terminal window.

  14. Copy the URL next to "cloneUrlHttp":, and be careful not to copy the quotation marks.

  15. Run the following command to clone the repository to the server:

    git clone [paste the URL you just copied]
  16. Enter the Git credentials username from the file downloaded earlier for the username prompt.

  17. Enter the Git credentials password from the file downloaded earlier for the password prompt.

  18. Check the clone:

    ls
    1. Go into the repo directory:
    cd RepoFromCLI
  19. Look for files in the repo:

    ls
  20. Run the following command to create a local text file:

    vim test.txt
  21. Hit i to enter insert mode and type the text:

    This is just a test of working with CodeCommit from the CLI
  22. Hit the Escape key, type :wq!, and press Enter.

  23. Add the file to Git:

    git add test.txt
  24. Commit the file to the local repository:

    git commit -m "added test.txt"
  25. Verify the file was committed:

    git log
  26. Push the change to the CodeCommit repository:

    git push -u origin main
  27. Enter the Git credentials username from the file downloaded earlier for the username prompt.

  28. Enter the Git credentials password from the file downloaded earlier for the password prompt.

  29. Refresh the AWS Management Console view of the CodeCommit repository for RepoFromCLI and verify the new file was uploaded.

Additional Resources

Log in to the live AWS environment using the credentials provided.

Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?