In the upcoming blogs, we will be making a CI/CD pipeline on AWS with these tools: -
CodeCommit
CodeBuild
CodeDeploy
CodePipeline
Let's dive in today with AWS CodeCommit.✨
What is AWS CodeCommit?
AWS CodeCommit
is a fully-managed source control service that hosts secure Git-based repositories. It makes it easy for teams to collaborate on code in a secure and highly scalable ecosystem, exploiting the benefits of CI/CD. It eliminates the need for a third party version control.
CodeCommit
eliminates the need to operate your own source control system or worry about scaling its infrastructure. You can use CodeCommit to securely store anything from source code to binaries, and it works seamlessly with your existing Git tools.
In other words, CodeCommit
is a managed source control service by AWS that allows users to store, manage, and version their source code and artifacts securely and at scale. It supports Git, integrates with other AWS services, enables collaboration through branch and merge workflows, and provides audit logs and compliance reports to meet regulatory requirements and track changes. Overall, CodeCommit provides developers with a reliable and efficient way to manage their codebase and set up a CI/CD pipeline for their software development projects.
Features of AWS CodeCommit
Several features of AWS CodeCommit include: -
Fully Managed Service
: AWS CodeCommit eliminates the boring tasks of managing your resources providing high service availability and durability.Store Code Securely
: Since its a version control system, it stores your code. For a matter of fact, it stores any kind of data, be it documents or binary files. Data stored is pretty secure as they’re encrypted at rest as well as in transit.Work Collaboratively With Code
: AWS CodeCommit lets you collaboratively work with the code. You can work on a section of the code and the other person/team can work on the other section, the changes/updates can be pushed and merged in the repository. Users can review, comment on each other’s code helping them write code to their highest potential.Highly Scalable
: AWS CodeCommit lets you scale up or down to meet your needs. The service can handle large repositories, a large number of files with large branches and lengthy commit histories.Integration
: You can easily integrate AWS CodeCommit with other AWS services. It keeps these services close to other resources making it easier and faster to fetch and use increasing the speed and frequency of development life cycle. It also lets you integrate third-party services pretty easily.Migration
: You can easily Migrate any Git-based repository to CodeCommit easily.Interactions Using Git
: Interacting with CodeCommit is pretty simple as its Git-based. You can use Git Commands to pull, push, merge or perform other actions. It also gives you the feature to use AWS CLI commands along with its very own API’s.Cross-Account Access
: CodeCommit lets you cross-link two different AWS accounts making it easier to share repositories between two accounts securely. There are a few things to keep in mind like you shouldn’t share your ssh keys or AWS credentials.
AWS CodeCommit vs GitHub
GitHub
is also one of the version control systems. Let’s first look at the similarities between GitHub and CodeCommit.
CodeCommit and GitHub use Git repositories.
Both of them support code review.
They can be integrated with AWS CodeBuild.
Both of them use two methods of authentications, SSH and HTTPS.
Let's now have a look at the differences between them.
Security
: Git is administered using GitHub users while CodeCommit uses AWS’s IAM Roles and users. This makes it highly secure. Using IAM roles lets you share your repositories with only specific people while letting you limit their access to the repository. For example, few users can view the repository, few people can make edits, etc. CodeCommit lets you have a third step authentication using MFA.Hosting
: Git is like home for GitHub but not when used with AWS. Hence when GitHub is used with AWS, it’s like a third-party tool. Whereas, CodeCommit is hosted on AWS and managed by AWS, making integrations with CodeBuild and its usage much simpler.User Interface
: GitHub is fully featured and has a really nice UI. Whereas CodeCommit user interface is pretty average.
AWS CodeCommit Workflow
Have a look at the below flow diagram to understand the workflow of CodeCommit. It consists of three parts — Development Machine, AWS CLI/CodeCommit Console, AWS CodeCommit Service.
You can use the AWS CLI or AWS CodeCommit Console to create a repository(remote) which will be reflected onto your AWS CodeCommit Service to start off with your project.
Do a git clone from your development machine, a git clone request will be received at the CodeCommit service end. This will end up syncing the remote repository created in step 1 and the local repository that was just cloned.
Use the local repository on the development machine to modify the code. Run git add to stage the modified files locally, git commit to commit the files locally and git push to push the modified changes to CodeCommit. This will, in turn, modify the remote repository.
Download changes or modifications that are done by other team members working on the same repository using git pull. Update the remote repository and send those updates to your development machine to keep the local repository updated.
Tasks
Task 1: Set up a code repository on CodeCommit and clone it on your local.
Step 1: Login to AWS Console and on Search bar type "CodeCommit".
Step 2: Go to CodeCommit. You will see the below page.
Step 3: Click on "Create repository" and Setup your Code Repository.
Give name for your Repo.
Step 4: Click on Create.
Step 5: Now, Generate Git credentials. Go to IAM Service.
Step 6: Click on “Users” in the left navigation pane.
Step 7: Click on Create User.
Checkbox for Provide user access to the AWS Management Console — optional
Select I want to create an IAM user and give password
Click on Next.
Step 8: In the Set Permissions.
Click on Attach Policies Directly
Select the policy
AWSCodeCommitFullAccess
Click on Next.
Step 9: Review the details and Click on Create User.
Step 10: Download the .csv file since this is the only time you can view and download this password.
Step 11: Open the User you created. Go to the Security Credentials tab.
Step 12: Scroll down to HTTPS Git credentials for AWS CodeCommit. Select Generate Credentials.
Step 13: Download credentials and click on Close.
This is the Git credentials for accessing CodeCommit.
Step 14: Now, Clone the repository from CodeCommit. In the CodeCommit dashboard, click on HTTPS to copy the URL.
Step 15: At your instance terminal, clone your repo using below URL.
git clone <https>
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/CodeCommit-Repo
For the prompt, give the CodeCommit credentials you downloaded earlier.
Step 16: Go to the repo directory you created now using the cd command.
Yes! You have created an empty repository in AWS CodeCommit and cloned it to your local.🎉😎
Task 2: Add a new file from local and commit to your local branch. Push the local changes to the CodeCommit repository.
Step 1: Add a new file from local and commit to your local branch.
Create five files using the below command.
touch file{01..05}.txt
Step 2: Add these files to the staging area, using the below git commands
git status
git add .
git status
Step 3: To add these in the local repositories history, use the below commad.
git commit -m "Commiting the files I created now"
Step 4: Now, Push the changes to the CodeCommit repository using the below command.
git push origin master
Step 5: Verify that the files are pushed into the CodeCommit repository.
In the CodeCommit Repository > Repositories > Code.
And yes! You have pushed your local files to the CodeCommit Repository.🎉😎
Conclusion
In Conclusion, AWS CodeCommit
is a fully-managed source control service provided by Amazon Web Services (AWS). It allows users to securely store and manage their source code repositories in the cloud.
CodeCommit
supports popular version control systems like Git, enabling collaborative software development with features such as branching, merging, and pull requests. With its integration into the AWS ecosystem, CodeCommit facilitates seamless development workflows, CI/CD processes, and collaboration among distributed teams.
Its scalability, security measures, and the ability to easily integrate with other AWS services make AWS CodeCommit
a valuable solution for version control in cloud-based development environments.
In this blog, We have created a repository in CodeCommit, Cloned it to the local, and pushed the files from local to the CodeCommit.
Hope you find it helpful🤞 So I encourage you to try this on your own and let me know in the comment section👇 about your learning experience.✨
👆The information presented above is based on my interpretation. Suggestions are always welcome.😊
~Smriti Sharma✌