AWS CodeCommit with CLI and GIT
This tutorial will help you configure the necessary things required to work with CodeCommit from CLI. Also you will learn how to install Git and access the CodeCommit Repo from Git.
We will perform the following actions —
1. Configure CLI for programmatic AWS access.
2. Create a CodeCommit repository.
3. Upload sample file to the repository.
4. Generate the HTTPS Git credentials for AWS CodeCommit.
5. Install git.
6. Clone the created repository from CodeCommit to your machine.
7. Create a new file and push the changes to CodeCommit repository.
Prerequisites:
1. Install AWS CLI . Follow this to Install AWS CLI.
2. IAM permissions to create and manage CodeCommit repository.
— — — — — — — — — — — — — — — — — — — — — — — — — —
Configure CLI for programmatic AWS access:
aws configure
— — — — — — — — — — — — — — — — — — — — — — — — — —
Create a CodeCommit Repository:
Run the below command to create a repository.
#Modify the name and description before execution
aws codecommit create-repository \
--repository-name myCodeRepo791 \
--repository-description "CodeCommit Demo repository"
Go to the AWS Console, open CodeCommit > Repositories. You will be able to find the newly created repository.
Copy the HTTPS URL. This URL will be used later.
— — — — — — — — — — — — — — — — — — — — — — — — — —
Upload a sample file to the repository:
- Click on the myCodeRepo791 repository to open it.
- Click Add file > Upload file.
- Click Choose file.
- Select a sample file from your machine.
- Enter your name as author name and your email as the email address.
- Click Commit changes.
— — — — — — — — — — — — — — — — — — — — — — — — — —
Generate the HTTPS Git credentials for AWS CodeCommit:
Go to the AWS Console>IAM>Users> Click on your identity.
Scroll down to the section ‘HTTPS Git credentials CodeCommit’ and Click on Generate Credentials. Save the credentials.
— — — — — — — — — — — — — — — — — — — — — — — — — —
Install git.
Use the below command to install git on Amazon Linux 2 machine.
sudo yum install git -y
Follow this if you are using other machines. Git — Installing Git (git-scm.com)
— — — — — — — — — — — — — — — — — — — — — — — — — —
Clone the repository to your machine.
Run the following command to clone the repository to your machine.
git clone [Paste the Cloned URL]
Provide the username and password. You will get it from the downloaded csv file that was previously generated from IAM console.
See the file and folders. myCodeRepo791 has been cloned to local system.
— — — — — — — — — — — — — — — — — — — — — — — — — —
Create a new file and push the changes to CodeCommit repository:
Run the following command to create a text file.
vim LocalSampleFile.txt
Press i
to enter insert mode and type any text. Hit the Escape key, type :wq!
, and press Enter.
Add the file to Git.
git add LocalSampleFile.txt
Commit the file to the local repository.
git commit -m "added LocalSampleFile.txt"
Verify the commit, see logs.
git log
Push the change to the CodeCommit repository.
git push -u origin main
Enter the Git credential username and password. Find it from the credential file downloaded earlier.
Go to the CodeCommit repository refresh it and you will be able to see the newly added file.
— — — — — — — — — — — — — — — — — — — — — — — — — —
Thanks for your time. Enjoy :)
Have a look at my other blogs -