AWS CodeCommit is a highly scalable, managed source control service that hosts private Git repositories. CodeCommit stores your data in Amazon S3 and Amazon DynamoDB giving your repositories high scalability, availability, and durability. You simply create a repository to store your code. There is no hardware to provision and scale or software to install, configure, and operate.
This lab demonstrates how to:
- Create a code repository using AWS CodeCommit via the Amazon Management Console
- Create a local code repository on the Linux instance using git
- Synchronize a local repository with an AWS CodeCommit repository
In this task, you use the AWS Management Console to create an AWS CodeCommit repository.
- At the top of the AWS Management Console, in the search bar, search for and choose
CodeCommit
. - On the AWS CodeCommit page, choose
Create repository
. - On the Create repository page:
- For Repository name, enter
My-Repo
. - For Description enter
My first repository
. - Choose
Create
.
- For Repository name, enter
An Amazon EC2 instance has been created for you as part of the lab environment build process. In this task, you connect to the instance using AWS Systems Manager Session Manager.
- Copy the Ec2InstanceSessionUrl value from the list to the left of these instructions, and then paste it into a new web browser tab. A console connection is made to the instance inside your web browser window. A set of commands are run automatically when you connect to the instance that change to the user’s home directory and display the path of the working directory, similar to this:
This task provides an example of how you would use AWS CodeCommit to synchronize to any local code repository that you might create in your normal production development environment.
- In the terminal session, run the following command to install the Git client:
sudo yum install -y git
- Run the following commands to configure the Git credential helper with the AWS credential profile, and allow the Git credential helper to send the path to repositories:
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
These commands have no output.
Next, obtain the HTTPS URL of your AWS CodeCommit repository.
- Return to your web browser tab with the AWS CodeCommit console, which should be on the My-Repo page.
- At the upper-right of the page, choose
Clone URL
, and then choose Clone HTTPS.
The repository URL is copied to your clipboard and should look similar to this: https://git-codecommit.us-east-1.amazonaws.com/v1/repos/My-Repo.
- Return to your web browser tab with the terminal session.
- Run the following command to clone the My-Repo repository to the instance:
- Replace the CLONE_HTTPS_URL placeholder value with the Clone HTTPS URL that you copied previously.
git clone CLONE_HTTPS_URL
The output should indicate that you are cloning the My-Repo repository, and that the repository is empty, similar to this:
Cloning into 'My-Repo'...
warning: You appear to have cloned an empty repository.
In this task, you create your first commit in your local repo. You create two example files in your local repo, use Git to stage the changes to your local repo, and then commit the changes.
- Run the following command to change to the My-Repo directory:
cd ~/My-Repo
- Run the following command to create two files in your local repo:
echo "The domestic cat (Felis catus or Felis silvestris catus) is a small, usually furry, domesticated, and carnivorous mammal." >cat.txt
echo "The domestic dog (Canis lupus familiaris) is a canid that is known as man's best friend." >dog.txt
- Run the following command to stage the changes in your local repo and see them staged, then commit those changes:
git add cat.txt dog.txt
git status
git commit -m "Added cat.txt and dog.txt"
- Run the following command to push your commit through the default remote name Git uses for your AWS CodeCommit repository (origin), from the default branch in your local repo (master):
git push -u origin master
After you have pushed code to your AWS CodeCommit repository, you can view the contents using the AWS CodeCommit console.
- Return to your web browser tab with the AWS CodeCommit console, which should be on the My-Repo page.
- Choose your web browser’s refresh button to refresh the page. The two files that you added to your repository should be displayed.
- Choose the link for each file to view its contents.