DEV Community

Cover image for AWS CodeCommit
Shrihari Haridass
Shrihari Haridass

Posted on

AWS CodeCommit

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

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

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

Image description

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

-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

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

Image description

Image description

-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

Image description

-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

-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

Image description

-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

-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

-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

Image description

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

Image description

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

Image description

Image description

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

Image description

-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

Image description

-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

Image description

Image description

Image description

Image description

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

Top comments (0)