Menu
AWS Cloud9
User Guide

AWS CodeCommit Sample for AWS Cloud9

This sample enables you to set up an AWS Cloud9 development environment to interact with a remote code repository in AWS CodeCommit. AWS CodeCommit is a source code control service that enables you to privately store and manage Git repositories in the AWS Cloud. For more information about AWS CodeCommit, see the AWS CodeCommit User Guide.

Note

This sample assumes you already have the AWS Cloud9 IDE for your AWS Cloud9 development environment open in your web browser. To create an environment, see Creating an Environment.

Creating this sample may result in charges to your AWS account. These include possible charges for services such as Amazon EC2 and AWS CodeCommit. For more information, see Amazon EC2 Pricing and AWS CodeCommit Pricing.

Step 1: Set Up Your IAM Group with Required Access permissions

If your AWS credentials are associated with an IAM administrator user in your AWS account, and you want to use that user to work with AWS CodeCommit, skip ahead to Step 2: Create a Repository in AWS CodeCommit.

  1. Sign in to the AWS Management Console, if you are not already signed in.

    For this step, we recommend you sign in using credentials for an IAM administrator user in your AWS account. If you cannot do this, check with your AWS account administrator.

  2. Open the IAM console. To do this, in the console's navigation bar, choose Services. Then choose IAM.

  3. Choose Groups.

  4. Choose the group's name.

  5. On the Permissions tab, for Managed Policies, choose Attach Policy.

  6. In the list of policy names, select one of the following boxes:

    • Select AWSCodeCommitPowerUser for access to all of the functionality of AWS CodeCommit and repository-related resources, except it does not allow deletion of AWS CodeCommit repositories or create or delete repository-related resources in other AWS services, such as Amazon CloudWatch Events.

    • Select AWSCodeCommitFullAccess for full control over AWS CodeCommit repositories and related resources in the AWS account, including the ability to delete repositories.

    (If you don't see either of these policy names in the list, type the policy name in the Filter box to display it.)

  7. Choose Attach Policy.

To see the list of access permissions that these AWS managed policies give to a group, see AWS Managed (Predefined) Policies for AWS CodeCommit in the AWS CodeCommit User Guide.

Step 2: Create a Repository in AWS CodeCommit

In this step, you create a remote code repository in AWS CodeCommit by using the AWS CodeCommit console.

If you already have an AWS CodeCommit repository, skip ahead to Step 3: Connect Your Environment to the Remote Repository.

To create the repository

  1. If you are signed in to the AWS Management Console as an IAM administrator user from the previous step, and you do not want to use the IAM administrator user to create the repository, sign out of the AWS Management Console.

  2. Open the AWS CodeCommit console, at https://console.aws.amazon.com/codecommit.

  3. In the console's navigation bar, use the region selector to choose the AWS Region you want to create the repository in (for example, US East (Ohio)).

  4. If a welcome page is displayed, choose Get started. Otherwise, choose Create repository.

  5. On the Create repository page, for Repository name, type a name for your new repository, for example MyDemoCloud9Repo. If you choose a different name, substitute it throughout this sample.

  6. (Optional) For Description, type something about the repository, for example This is a demonstration repository for the AWS Cloud9 sample.

  7. Choose Create repository. A Connect to your repository pane is displayed. Choose Close, as you will connect to your repository in a different way later in this topic.

Step 3: Connect Your Environment to the Remote Repository

In this step, you use the AWS Cloud9 IDE to connect to the AWS CodeCommit repository you created or identified in the previous step.

Complete one of the following sets of procedures, depending on the type of AWS Cloud9 development environment you have.

Environment type Follow these procedures

EC2 environment

  1. From a terminal session in the IDE, run the following 2 commands:

    Copy
    git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true

    For more information, see Step 2: Configure the AWS CLI Credential Helper On Your AWS Cloud9 EC2 Development Environment in Integrate AWS Cloud9 with AWS CodeCommit in the AWS CodeCommit User Guide.

  2. Skip ahead to Step 4: Clone the Remote Repository into Your Environment, later in this topic.

SSH environment

  1. If Git is not already installed in the environment, use a terminal session in the IDE to install it. For more information, see Step 2: Install Git in Setup Steps for SSH Connections to AWS CodeCommit Repositories on Linux, macOS, or Unix in the AWS CodeCommit User Guide.

  2. Complete Step 3: Configure Credentials on Linux, macOS, or Unix in Setup Steps for SSH Connections to AWS CodeCommit Repositories on Linux, macOS, or Unix in the AWS CodeCommit User Guide.

    When you are instructed to sign in to the AWS Management Console and open the IAM console, we recommend you sign in using credentials for an IAM administrator user in your AWS account. If you cannot do this, check with your AWS account administrator.

  3. Skip ahead to Step 4: Clone the Remote Repository into Your Environment, later in this topic.

Step 4: Clone the Remote Repository into Your Environment

In this step, you use the AWS Cloud9 IDE to clone the remote repository in AWS CodeCommit into your environment.

To clone the repository, run the git clone command, supplying the repository's clone URL, shown here as CLONE_URL .

Copy
git clone CLONE_URL

For an EC2 environment, you supply an HTTPS clone URL that starts with https://. For an SSH environment, you supply an SSH clone URL that starts with ssh://.

To get the repository's full clone URL, see Use the AWS CodeCommit Console to View Repository Details in the AWS CodeCommit User Guide.

If your repository doesn't have any files in it, a warning message is displayed, such as You appear to have cloned an empty repository. This is expected behavior, which you will address later.

Step 5: Add Files to the Repository

In this step, you create three simple files in the cloned repository in your environment. Then you add the files to the Git staging area in your cloned repository, commit the staged files, and push the commit to your remote repository in AWS CodeCommit.

If the cloned repository already has files in it, you're done and can skip the rest of this sample.

To add files to the repository

  1. Create a new file. On the menu bar, choose File, New File.

  2. Type the following content into the file, and then choose File, Save to save the file as bird.txt in the MyDemoCloud9Repo directory in your environment.

    Copy
    bird.txt -------- Birds are a group of endothermic vertebrates, characterized by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton.

    Note

    To confirm you are saving this file in the correct directory, in the Save As dialog box, choose the MyDemoCloud9Repo folder, and be sure Folder displays /MyDemoCloud9Repo.

  3. Create two more files, named insect.txt and reptile.txt, with the following content, and saving them in the same MyDemoCloud9Repo directory.

    Copy
    insect.txt ---------- Insects are a class of invertebrates within the arthropod phylum that have a chitinous exoskeleton, a three-part body (head, thorax, and abdomen), three pairs of jointed legs, compound eyes, and one pair of antennae.
    Copy
    reptile.txt ----------- Reptiles are tetrapod (four-limbed vertebrate) animals in the class Reptilia, comprising today's turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives.
  4. In the terminal, run the cd command to switch to the MyDemoCloud9Repo directory.

    Copy
    cd MyDemoCloud9Repo
  5. Confirm the files were successfully saved in the MyDemoCloud9Repo directory by running the git status command. All three files will be listed as untracked files.

    Copy
    Untracked files: (use "git add <file>..." to include in what will be committed) bird.txt insect.txt reptile.txt
  6. Add the files to the Git staging area by running the git add command.

    Copy
    git add --all
  7. Confirm the files were successfully added to the Git staging area by running the git status command again. All three files are now listed as changes to commit.

    Copy
    Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: bird.txt new file: insect.txt new file: reptile.txt
  8. Commit the staged files by running the git commit command.

    Copy
    git commit -m "Added information about birds, insects, and reptiles."
  9. Push the commit to your remote repository in AWS CodeCommit by running the git push command.

    Copy
    git push -u origin master
  10. Confirm whether the files were successfully pushed. Open the AWS CodeCommit console, if it isn't already open, at https://console.aws.amazon.com/codecommit.

  11. In the top navigation bar, near the right edge, choose the AWS Region where you created the repository (for example, US East (Ohio)).

  12. On the Dashboard page, choose MyDemoCloud9Repo. The three files are displayed.

To continue experimenting with your AWS CodeCommit repository, see Browse the Contents of Your Repository in the AWS CodeCommit User Guide.

If you're new to Git and you don't want to mess up your AWS CodeCommit repository, experiment with a sample Git repository on the Try Git website.

Step 6: Clean Up

To prevent ongoing charges to your AWS account after you're done using this sample, you should delete the AWS CodeCommit repository. For instructions, see Delete an AWS CodeCommit Repository in the AWS CodeCommit User Guide.

You should also delete the environment. For instructions, see Deleting an Environment.