Table of contents
What is CodeCommit & what are its features?
AWS CodeCommit is a fully managed source code control service provided by Amazon Web Services (AWS). It is designed to help development teams securely store and manage their source code repositories in the cloud. CodeCommit is similar in functionality to popular version control systems like Git, but it is tightly integrated with AWS services, making it well-suited for building and deploying applications on AWS infrastructure.
Here are some key features and characteristics of AWS CodeCommit:
Git-Compatible: CodeCommit is compatible with Git, which means you can use standard Git commands and workflows with CodeCommit repositories. Developers can use their existing Git skills and tools with CodeCommit.
Secure and Scalable: CodeCommit provides secure and scalable repositories. It supports AWS Identity and Access Management (IAM) for access control, and data is encrypted both in transit and at rest. It can handle large repositories and is designed to scale with your needs.
Fully Managed: AWS takes care of the underlying infrastructure, including hardware maintenance, data replication, and backups. This allows your development teams to focus on writing code rather than managing repositories.
Integration with AWS Services: CodeCommit integrates seamlessly with other AWS services, such as AWS CodeBuild, AWS CodeDeploy, AWS CodePipeline, and AWS Cloud9, to enable a complete end-to-end DevOps workflow.
Collaboration Features: CodeCommit supports collaboration features like pull requests, which allow developers to propose and review code changes before they are merged into the main codebase.
Branching and Versioning: You can create branches in your repositories to work on different features or bug fixes independently. This branching and versioning support is crucial for team collaboration and code management.
Triggers and Notifications: CodeCommit allows you to set up triggers that can initiate actions when code changes are pushed to the repository. You can configure notifications and automate workflows based on these triggers.
Task-01 :
Set up a code repository on CodeCommit and clone it on your local.
Login to AWS account and Select CodeCommit
Proceed further to create a repository
Enter name, and description and simply create.
A Repo has been created
A warning will show up - "You are signed in using a root account. You cannot configure SSH connections for a root account, and HTTPS connections for a root account are not recommended. Consider signing in as an IAM user and then setting up your connection."
This means that using a root AWS account should be avoided for SSH or HTTPS connections. Instead, create and use an IAM user for better security and control over access to AWS services.
Set up GitCredentials in your AWS IAM.
To do so, go to IAM service on AWS and create an IAM user
On IAM dashboard, select "Users" and click on "Create user"
Enter the user name, select AWS management console, Usertype- IAM user and proceed further.
You can add the user to a group if any, else proceed further.
You can see below that the user- mydemo has only 1 permission- "IAMUserChangePassword". It means that the user can only change password.
Proceed further to create the user.
It's always a good practice to download the .csv file on your local system that contains your credentials.
Now to provide CodeCommit access to the user- "mydemo", this can done by using credentials under "Security Credentials"
Scroll down & generate credentials under - "HTTPS Git credentials for AWS CodeCommit"
The credentials can be downloaded on the local system.
Now go back to Code Commit --> Repositories
Select the repository
Click on "Clone URL" located on the top right of the screen.
Select Clone HTTPS
The URL has been created successfully
Use credentials in your local and then clone the repository from CodeCommit
Using above created link you can clone the repository on your local system.
URL- https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo
Enter CodeCommit credentials
Despite entering the credentials we get an error : 403. Unable to access.
To solve this error, go to IAM and add permissions:
Select "Attach policies directly" and add AWSCodeCommitPowerUser
Click "Next", Review and Add permissions.
URL- https://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo
The warning shows that you have cloned an empty repo which means that the clone is working.
Task-02 :
Add a new file from local and commit to your local branch
Create a sample HTML file in the local system and Initialize git.
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
To Initialize use the below command:
git init
To check the status:
git status
You can now commit the file using the command:
git commit -m "My message"
Push the local changes to the CodeCommit repository.
To push the file to CodeCommit use the command
git push origin master
The file is now reflected on CodeCommit
This is the way to connect the local system files with AWS using IAM CodeCommit
Conclusion:
In this blog post, I've walked you through the process of connecting our local development environment to AWS CodeCommit, which is a fantastic and secure service for managing our source code. By making use of IAM users and HTTPS Git credentials, we've taken important steps to ensure the security of our code. Thanks to CodeCommit, we now have the ability to effortlessly handle our code repositories in the cloud.
Reference:
CI/CD pipeline on AWS: Part-2
aminchivilkar.hashnode.dev/day-69-cicd-pipeline-on-aws-part-2
Hope you like my post. Don't forget to like, comment, and share.