AWS CodeCommit
Tags: aws, awsdevops, devops, cloud
Published: 2024-01-17 04:40:00

As you can see in the title, today we are covering the first service of AWS DevOps, which is 'CodeCommit.' I hope you've read the introduction part of this series; if not, please check it out. AWS CodeCommit is similar to other centralized code repositories like GitHub, GitLab, GitBucket, and so on; the only difference is that it's an AWS private repository that you can use. For more information, you can read about it on [AWS CodeCommit](https://aws.amazon.com/codecommit/.)

So today, we'll learn how to create a repository in CodeCommit, create a user for it, provide necessary permissions to that user using the IAM service, clone that repository into our local machine, make some changes, and push it back to the repository. Additionally, we'll explore how to create branches, merge them in CodeCommit, and cover some other important options. Let's get started!

-1-. Begin by searching for the 'CodeCommit' service. As you know, the first step involves pushing code into the repository.

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

-2-. Next, navigate to 'Repository,' where we push our code. To do this, click on 'Create Repository.'

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

Then, provide a name and description for the repository. You'll notice 'CodeGuru,' which is similar to 'SonarQube Scanner' for code scanning. However, at this point, we don't want to proceed directly to 'create repository.'

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

-3-. You'll encounter a warning indicating that using the root user is not recommended. To address this, let's create another user in 'IAM' to enable the use of services in AWS DevOps. Proceed to 'IAM' now.

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

-4-. In 'IAM,' navigate to 'Users,' click on 'Add Users,' and provide a name for the user.

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

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

-5-. In the 'Set Permissions' window, click 'Next.' On the 'Review' page, you'll notice that we currently have only one permission, which is the ability to change the password. Proceed to click 'Create User.'

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

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

-6-. You can save this password, as it is displayed only once, or download the '.csv file.'

-7-. Now that our user is created, click on it. We want to grant permissions for 'CodeCommit,' so first, navigate inside it and then click on 'Security Credentials.'

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

-8-. Scroll down, and you'll find 'HTTPS Git credentials for AWS CodeCommit.' Click on 'Generate Credentials.' Here, you will see your credentials generated. You can also download them, and with these credentials, you can access.

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

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

-9-. Return to the 'CodeCommit' window, click on 'Clone URL,' and choose the 'HTTPS' option. Create a folder, open your preferred code editor (like VS Code), and clone the repository to your local computer.

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

-10-. While cloning, a pop-up will appear asking you to enter the Git credentials created for 'CodeCommit.' Simply copy and paste them in this window.

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

-11-. If the cloning process is not working, we might have missed setting up IAM permissions for cloning and committing. Go back to the 'Users' section, select the user, navigate to the 'Permissions' tab. As there is only one permission currently, click on 'Add permission' → 'Attach Policy Directly' → 'AWSCodeCommitPowerUsers.'

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

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

-12-. Now, try the process again in 'VS Code.' This time, you should see a 'Clone successful, empty repository' message.

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

-13-. Next, add an 'index.html' file with some sample text. After making changes, commit and push this code into our repository.

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

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

-14-. Navigate to 'CodeCommit' → 'Repository,' and refresh. You should now see our files in the repository.

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

-15-. This is how you can connect your local machine to AWS CodeCommit using IAM credentials, similar to connecting to GitHub. Now, let's create another branch, push the code, and check the 'Branches' section in CodeCommit to see the newly created 'dev' branch.

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

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

-16-. Now, let's merge the changes into 'Master.' Click on the branch, create a pull request, provide a name, create the pull request, merge it using fast-forward, and delete the source branch after merging. Refresh the 'Master' branch to see your changes successfully merged.

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

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

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

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

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

-17-. So, this is how you can use the 'CodeCommit' service.