Getting Started with AWS CodeCommit: A Step-by-Step Guide
Tags: aws, codecommit, ec2, git
Published: 2023-10-14 22:14:26


###Introduction:

This article is your personal guide to embracing the power of AWS CodeCommit. We will create AWS CodeCommit repository, connect to an Amazon EC2 instance, set up a local Git repository, make significant code changes, and relish the thrill of your first commit. This journey goes beyond step-by-step instructions; it's about equipping you with the skills and insights you need to master the intricacies of contemporary software development.



**Task 1: Create an AWS CodeCommit repository**

1. **Access the AWS Management Console**
   - To begin, navigate to the AWS Management Console and search for "CodeCommit."
   - Select "CodeCommit" to access the service.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y65o9x2fjiv73hrwz6j7.png)

2. **Create a Repository**
   - Click on "Create repository" within the CodeCommit service.
   - Provide a unique name for your repository, for example, "My-Repo."
   - Optionally, add a description like "My first repository."
   - Confirm the creation by clicking "Create."

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rczbx137seity7hqp12r.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f43hwa6jv2h57se8xx6h.png)


**Task 2: Connect to the Amazon EC2 Instance**

1. **Access the EC2 Instance**
   - As part of this lab, an EC2 instance has already been provisioned for you.

2. **Establish a Console Connection**
   - Copy the "Ec2InstanceSessionUrl" value from the instructions.
   - Open a new web browser tab and paste the URL.
   - This will establish a console connection to your EC2 instance.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1565d07ykde4sdmvv9nh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1i4ew0qpqkih77b0ntp.png)



**Task 3: Create a Local Repository Using Git**

1. **Install Git on EC2 Instance**
   - Within the EC2 instance terminal session, run the command: `sudo yum install -y git`.

2. **Configure Git Settings**
   - Configure the Git credential helper to work with AWS CodeCommit and enable the use of HTTP paths.

3. **Clone AWS CodeCommit Repository**
   - Retrieve the HTTPS URL of your AWS CodeCommit repository from the AWS CodeCommit console.
   - Use the `git clone` command to clone the repository to your EC2 instance.


**Task 4: Making a Code Change and First Commit to the Repo**

1. **Navigate to the Repository Directory**
   - Change to the directory where you cloned the repository using `cd ~/My-Repo`.

2. **Create Example Files**
   - Use the `echo` command to create two example files in your local repository.

3. **View List of Files**
   - Check the files in the directory using the `ls` command.

4. **Stage Changes**
   - Stage the created files for commit using `git add`.

5. **Check Repository Status**
   - Use `git status` to view the status of your repository and the staged changes.

6. **Commit Changes**
   - Commit the staged changes with a meaningful message using `git commit -m "Added cat.txt and dog.txt"`.

7. **View Commit Details**
   - To review the details of your commit, execute `git log`.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rcnfqqfv997datgxjqey.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kckcqiaym5736ogmblt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgjar104np5an55abriw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7i21o9vfddeknpbr8h8v.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1hffoqln47bmr0n8i33.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9i19mozgkyfn2aaqjwp.png)

**Task 5: Push Your First Commit**

1. **Push Commit to AWS CodeCommit Repository**
   - Push the commit from your local repository to your AWS CodeCommit repository using `git push -u origin master`.

2. **View the Repository in CodeCommit Console**
   - Return to the AWS CodeCommit console in your web browser.
   - Refresh the page to see the files you added to your repository.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfbi53sddave55vbdfls.png)

Conclusion:

Congratulations! By following these steps, you have successfully created a CodeCommit repository, connected to an EC2 instance, established a local Git repository, made code changes, and pushed your first commit. AWS CodeCommit offers a range of features for secure and efficient source code management, making it a valuable addition to your development workflow.

Are you eager to dive even deeper into AWS and continue your learning journey? AWS offers a fantastic opportunity to access free AWS Builder Labs to elevate your DevOps skills. You can explore these labs by visiting the following link: [Free AWS Builder Labs](https://training.resources.awscloud.com/modern-apps-traincert/elevate-your-devops-skills-with-3-free-aws-builder-labs?trk=0cb51f95-97e9-4be8-bbe0-363d446de75f&sc_channel=el).