AWS Codecommit: Version-Control service for Amazon Web Services

0
840
AWS Codecommit

AWS CodeCommit is a source code storage and version-control service for Amazon Web Services‘ public cloud customers. CodeCommit was designed to help IT teams collaborate on software development, including continuous integration and application delivery.

The AWS CodeCommit service allows an enterprise to securely import and host scalable, private Git code repositories. A developer creates a repository through the AWS command-line interface (CLI), software development kit or CodeCommit APIs. Git, an open-source version control system, integrates with CodeCommit repositories using its CLI and several Git clients. CodeCommit also supports several Git commands and works with Jenkins, an open source tool for continuous integration.

Repositories stored in AWS CodeCommit have no size limits and can scale to meet customer needs. A developer or Web designer can store any type of file up to 2 GB in CodeCommit.

AWS CodeCommit stores data in Amazon Simple Storage Service and Amazon DynamoDB. CodeCommit automatically encrypts files and repositories at rest through AWS Key Management Service. Additional security can be implemented by integrating CodeCommit with AWS Identity and Access Management, which allows an administrator to assign user-access policies and establish multi-factor authentication. An administrator can use either HTTPS or SSH to communicate with CodeCommit.

AWS Codecommit Tutorial

This aws codecommmit tutorial will guide you to get started with AWS codecommit service. To follow this tutorial, you need to have the latest AWS CLI installed on your system.

# apt-get install aws-cli –y                           # For ubuntu

It is always advisable to create an IAM user and attach a policy with required access to codecommit.

Creating a repository

Like you do in any source control system, the first step is to create a repository for your project. Use the following syntax for creating a repository in codecommit

# aws codecommit create-repository --repository-name foxutech --repository-description "Write a description about your project"
{
    "repositoryMetadata": {
        "cloneUrlSsh": "ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/foxutech",
        "lastModifiedDate": 1526653711.966,
        "Arn": "arn:aws:codecommit:us-west-2:400845174994:foxutech",
        "repositoryId": "ba32f8b5-fbdf-47b7-80a6-550f0f01a8c2",
        "accountId": "400845174994",
        "creationDate": 1526653711.966,
        "cloneUrlHttp": "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/foxutech",
        "repositoryName": "foxutech",
        "repositoryDescription": "Write a description about your project"
    }
}

Once the command execution is successful, it returns the output with the codecommit repo url for both ssh and http.

Authentication local git to codecommit

Next step is to configure your local git for authenticating against codecommmit. So that you will have permissions to clone, push and do all the remote repository related tasks. You can do that using the credential helper as shown below.

# git config --global credential.helper '!aws codecommit credential-helper $@’
# git config --global credential.UseHttpPath true

Common git config

# git config --global user.email contact@foxutech# git config --global user.name "foxutech"

Cloning the Repository

You can clone the remote codecommit repository to your local workstation using the normal git clone command and the repository url you got in the output section when you created the repository.

# git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/foxutech foxutech
Cloning into 'foxutech'...
Checking connectivity... done.

performing Common Git Functions

Now you have an empty repository cloned from codecommit. You can perform all the normal git operations as you perform with any git based source control system as shown below.

# touch test.txt
# git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        test

nothing added to commit but untracked files present (use "git add" to track)

Once you get the commit id, use the following command to create a new branch. Replace the repository name, branch name and commit id accordingly.

# aws codecommit create-branch --repository-name foxutech --branch-name tools --commit-id fde9b84a57847cad106faa1805c74068da278532

List all Branches

You can list all the branches associated with a repository using “list-branches” as shown below.

# aws codecommit list-branches --repository-name foxutech
{
    "branches": [
        "master",
        "tools"
    ]
}

Rename a Repository

A repository can be renamed using “update-repository-name” attribute.

# aws codecommit update-repository-name --old-name foxutech --new-name motoskia

Getting Repository Details

To get the information about more than one repository, you can run a batch-get-repositories attribute as shown below.

# aws codecommit batch-get-repositories --repository-names motoskia gocode
{
    "branches": [
        "master",
        "tools"
    ]
}
# aws codecommit update-repository-name --old-name foxutech --new-name motoskia
# aws codecommit batch-get-repositories --repository-names motoskia gocode
{
    "repositories": [
        {
            "repositoryName": "motoskia",
            "cloneUrlHttp": "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/motoskia",
            "creationDate": 1526653711.966,
            "lastModifiedDate": 1526655034.858,
            "defaultBranch": "master",
            "cloneUrlSsh": "ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/motoskia",
            "accountId": "400845174994",
            "Arn": "arn:aws:codecommit:us-west-2:400845174994:motoskia",
            "repositoryId": "ba32f8b5-fbdf-47b7-80a6-550f0f01a8c2",
            "repositoryDescription": "Write a description about your project"
        }
    ],
    "repositoriesNotFound": [
        "gocode"
    ]
}

Deleting a Repository

“delete-repository” attribute is used with the cli to delete a repository.

# aws codecommit delete-repository --repository-name motoskia
{
    "repositoryId": "ba32f8b5-fbdf-47b7-80a6-550f0f01a8c2"
}

NO COMMENTS