AWS CODECOMMIT CREATION AND ACCESS IT FROM AWS CLI

ABOUT AWS CODECOMMIT

AWS CodeCommit is a secure, highly scalable, managed source control service that hosts private Git repositories. It makes it easy for teams to securely collaborate on code with contributions encrypted in transit and at rest. CodeCommit eliminates the need for you to manage your own source control system or worry about scaling its infrastructure. You can use CodeCommit to store anything from code to binaries. It supports the standard functionality of Git, so it works seamlessly with your existing Git-based tools.

STEPS INVOLVED IN CREATING A AWS CODECOMMIT REPOSITORY AND AWS CLI CONFIGURATION

REQUIREMENT

  • AMI Linux system
  • A server user having access on aws codecommit service

CREATION OF EC2 INSTANCE

Launch a Linux AMI EC2 instance you can launch it without key pair as instant connect option , also make sure selected enable public IP assignment.

Right Click on the server and click on connect it will take to the EC2 Instance Connect option  click on connect  option.

It should launch the instance console in a new browser tab.

INSTALL GIT AND CREATE IAM CODECOMMIT CREDENTIALS

  • Select the newly created instance.
  • Click Connect at the top of the screen.
  • Leave the tab as EC2 Instance Connect and click Connect.
  • In the terminal, run the following command:
  • sudo yum update -y
  • Install Git:
  • sudo yum install git -y
  • Return to the the AWS Management Console.
  • Navigate to IAM > Users.
  • Click on cloud_user.
  • Click Add permissions > Attach existing policies directly.
  • Type “AWSCodeCommit” in the filter search box.
  • Select the AWSCodeCommitFullAccess policy.
  • Select the AWSCodeCommitFullAccess policy.
  • In the AWS Management Console, with cloud_user opened, click the Security credentials tab.
  • Under Access keys, click Create access key.
  • Click Download .csv file.
  • Click Close.
  • Under HTTPS Git credentials for AWS CodeCommit, click Generate
  • Click Download credentials.

Click Close.

CREATION OF REPOSITORY FROM CLI

Login to the server created type aws configure provide the access key ID and secret access key from the CSV downloaded under create access key option.

Once we are able to successfully able to connect using aws configure we can use below CLI command to create the repository.

aws codecommit create-repository –repository-name RepoFromCLI –repository-description “My demonstration repository”

  • In the AWS Management Console, open CodeCommit and refresh the screen.
  • Click on the RepoFromCLI repository link to open it.
  • Click Add file.
  • Click Upload file.
  • Click Choose file.
  • Select any small file from your machine you don’t mind uploading.
  • Enter your name under Author name and your email under Email address.
  • Click Commit changes.
  • Return to your terminal window.
  • Copy the URL next to “cloneUrlHttp”:, and be careful not to copy the quotation marks.
  • Run the following command to clone the repository to the server:
  • git clone [paste the URL you just copied]
  • Enter the Git credentials username from the file downloaded earlier for the username prompt.
  • Enter the Git credentials password from the file downloaded earlier for the password prompt.
  • Check the clone:
    ls
  • Go into the repo directory: cd RepoFromCLI
  • Look for files in the repo:
    ls
  • Run the following command to create a local text file:
    vim test.txt
  • Hit i to enter insert mode and type the text:
  • This is just a test of working with CodeCommit from the CLI
  • Hit the Escape key, type :wq!, and press Enter.
  • Add the file to Git:
  • git add test.txt
  • Commit the file to the local repository:
  • git commit -m “added test.txt”
  • Verify the file was committed:
  • git log
  • Push the change to the CodeCommit repository:
    git push -u origin main
  • Enter the Git credentials username from the file downloaded earlier for the username prompt.
  • Enter the Git credentials password from the file downloaded earlier for the password prompt.
  • Refresh the AWS Management Console view of the CodeCommit repository for RepoFromCLI and verify the new file was uploaded.

One thought on “AWS CODECOMMIT CREATION AND ACCESS IT FROM AWS CLI

Leave a Reply