What is CodeCommit ?
- 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.
Setup for HTTPS users using Git credentials
The simplest way to set up connections to AWS CodeCommit repositories is to configure Git credentials for CodeCommit in the IAM console, and then use those credentials for HTTPS connections. You can also use these same credentials with any third-party tool or integrated development environment (IDE) that supports HTTPS authentication using a static user name and password.
Step 1: Initial configuration for CodeCommit
Follow these steps to set up an Amazon Web Services account, create an IAM user, and configure access to CodeCommit.
To create and configure an IAM user for accessing CodeCommit
Create an IAM user, or use an existing one, in your Amazon Web Services account. Make sure you have an access key ID and a secret access key associated with that IAM user.
In the IAM console, in the navigation pane, choose Users, and then choose the IAM user you want to configure for CodeCommit access.
On the Permissions tab, choose Add Permissions.
In Grant permissions, choose Attach existing policies directly.
From the list of policies, select AWSCodeCommitPowerUser or another managed policy for CodeCommit access.
After you have selected the policy you want to attach, choose Next: Review to review the list of policies to attach to the IAM user. If the list is correct, choose Add Permissions.
Your User has created with Acess to AWSCodeCommit
Step 2: Create Git credentials for HTTPS connections to CodeCommit
In the IAM console, in the navigation pane, choose Users, and from the list of users, choose your IAM user.
On the user details page, choose the Security Credentials tab, and in HTTPS Git credentials for AWS CodeCommit, choose Generate.
Copy the user name and password that IAM generated for you, either by showing, copying, and then pasting this information into a secure file on your local computer, or by choosing Download credentials to download this information as a .CSV file. You need this information to connect to CodeCommit.
After you have saved your credentials, choose Close.
Note: This is your only chance to save the user name and password. If you do not save them, you can copy the user name from the IAM console, but you cannot look up the password. You must reset the password and then save it.
Setting Up a Code Repository on AWS CodeCommit:
Sign in to the AWS Management Console with newly created user and Open the CodeCommit Dashboard:
Navigate to the AWS Management Console and Sign in with your AWS account.
In the "Find Services" box, type “CodeCommit” and select the service.
Create a CodeCommit Repository:
Click on the "Create repository" button.
Provide a name for your repository.
Provide a description.
Click "Create"
Get Connection Details:
Once the repository is created, you will need to select how you want to connect to this repository. You will generally have two main options: HTTPS or SSH. For this example, let's go with HTTPS.
Click on the "Clone URL" drop-down and select "HTTPS".
Copy the HTTPS URL (You'll need this URL later to clone the repository).
Set Up Credentials and Clone Repository Locally
Install Git (if it isn’t already installed):
- Depending on your OS, use the appropriate package manager or download . Also you can refer installation steps from my blog : https://kshitijaa.hashnode.dev/git-hands-on-1
Install the AWS CLI (if it isn’t already installed):
- Follow the installation instructions on https://kshitijaa.hashnode.dev/iam-programmatic-access-and-aws-cli
Configure the AWS CLI:
- Run
aws configure
and provide the necessary AWS credentials (Access Key, Secret Key, Region). Ensure that these credentials have the necessary permissions for CodeCommit.
- Run
Configure Git with AWS Credentials Helper:
Run the following command to tell Git to use the AWS CLI as a credential helper:
git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true
Clone the Repository:
Navigate to the directory on your local machine where you want to clone the repository.
Use the HTTPS URL you copied earlier and run:
git clone [HTTPS_URL]
Replace
[HTTPS_URL]
with the URL you copied from the CodeCommit dashboard.
You should now have the repository cloned on your local machine, and you can start adding, committing, and pushing changes as with any other Git repository.
When clone, it does ask for Git Credentials, once provide it clone to local.
Remember, AWS IAM roles and permissions can be tricky, so ensure that the AWS credentials you use have the correct permissions to perform actions with CodeCommit. If you encounter permission errors, you might need to adjust your IAM policies accordingly.
Add a new file from local and commit to your local branch; Created manually
Adding the 1.txt file manually
Pushed the local changes to CodeCommit repository.
Go to AWS Management Console and validate
Here I see the same file and this is how you can establish the connection between CodeCommit and local!
This is how you create a repo in AWS using CodeCommit, Clone it to Local and Push your changes!
Stay Tuned! We have just started! 😃