{"id":667,"date":"2015-12-03T17:47:35","date_gmt":"2015-12-03T17:47:35","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=667"},"modified":"2015-12-03T17:47:35","modified_gmt":"2015-12-03T17:47:35","slug":"aws-codecommit-tutorial-beginners","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=667","title":{"rendered":"AWS Codecommit Tutorial &#8211; Beginners Guide"},"content":{"rendered":"<p>In a normal private environment , if you want to host your code using solutions like gitlab, Atlassian stash etc, you will need manage high availability and scalability for your production systems. AWS codecommit is a private managed source control system which is secure, highly scalable and scalable. It is git based and it works the same way like all other git based source control systems like github, stash etc. This allows easy migration of your code repositories to codecomiit and have the same work-flow you used to have. Moreover, codecommit provides out of the box encryption for your source codes which is at rest and in transit. If your applications are hosted in AWS, codecommit would be a good fit for all your source codes.<\/p>\n<h2 id=\"aws-codecommit-tutorial\">AWS Codecommit Tutorial<\/h2>\n<p>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. If you do not have the CLI setup follow this <a href=\"http:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/installing.html?ref=devopscube.com\">link<\/a> for the setup. It is always advisable to create an IAM user and attach a policy with required access to codecommit.<\/p>\n<p><strong>You Might Like:<\/strong> <a href=\"https:\/\/devopscube.com\/things-to-do-for-securing-aws-account\/\">AWS account security tips<\/a><\/p>\n<h3 id=\"creating-a-repository\">Creating a repository<\/h3>\n<p>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.<\/p>\n<pre><code>aws codecommit create-repository --repository-name MyProjecRepo --repository-description \"Write a description about your project\"<\/code><\/pre>\n<pre><code>devops@opsguy:~$ aws codecommit create-repository --repository-name myapp --repository-description \"This is the code repository for myapp\"\n{\n    \"repositoryMetadata\": {\n        \"repositoryName\": \"myapp\", \n        \"cloneUrlSsh\": \"ssh:\/\/git-codecommit.us-east-1.amazonaws.com\/v1\/repos\/myapp\", \n        \"lastModifiedDate\": 1449065689.399, \n        \"repositoryDescription\": \"This is the code repository for myapp\", \n        \"cloneUrlHttp\": \"https:\/\/git-codecommit.us-east-1.amazonaws.com\/v1\/repos\/myapp\", \n        \"creationDate\": 1449065689.399, \n        \"repositoryId\": \"2e859c05-06f6-458e-899d-cbc9a589fd33\", \n        \"Arn\": \"arn:aws:codecommit:us-east-1:146317666315:myapp\", \n        \"accountId\": \"146317666315\"\n    }\n}\ndevops@opsguy:~$ <\/code><\/pre>\n<p>Once the command execution is successfull, it returns the output with the codecommit repo url for both ssh and http.<\/p>\n<h3 id=\"authentication-local-git-to-codecommit\">Authentication local git to codecommit<\/h3>\n<p>Next step is to configure your local git for authenticating againist codecommmit. So that you will have persmissions to clone, push and do all the remote repository related tasks. You can do that using the credential helper as shown below.<\/p>\n<pre><code>git config --global credential.helper '!aws codecommit credential-helper $@'<\/code><\/pre>\n<pre><code>git config --global credential.UseHttpPath true\n<\/code><\/pre>\n<p><strong>Common git config<\/strong><\/p>\n<pre><code>devops@opsguy:~\/projects$ git config --global user.email \"contact@devopscube.com\"\ndevops@opsguy:~\/projects$  git config --global user.name \"devopscube\"<\/code><\/pre>\n<h3 id=\"cloning-the-repository\">Cloning the Repository<\/h3>\n<p>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.<\/p>\n<pre><code>devops@opsguy:~\/projects$ git clone https:\/\/git-codecommit.us-east-1.amazonaws.com\/v1\/repos\/myapp myrepo\nCloning into 'myrepo'...\nwarning: You appear to have cloned an empty repository.\nChecking connectivity... done.\ndevops@opsguy:~\/projects$<\/code><\/pre>\n<h3 id=\"performing-common-git-funtions\">performing Common Git Funtions<\/h3>\n<p>Now you have an empty repository clonned from codecommit. You can perform all the normal git operations as you perform with any git based source control system as shown below.<\/p>\n<blockquote><p><strong>Note:<\/strong> If you are using Ubuntu 14.04 as your workstation, you are likely to get a &#8220;<strong>gnutls_handshake() failed<\/strong>&#8221; error. You can rectify this error by following this solution. <a href=\"https:\/\/devopscube.com\/gnutls-handshake-failed-aws-codecommit\/\">gnutls_handshake() failed solution<\/a><\/p><\/blockquote>\n<pre><code>devops@opsguy:~\/projects\/myrepo$ touch test.txt\ndevops@opsguy:~\/projects\/myrepo$ git status\nOn branch master\n\nInitial commit\n\nUntracked files:\n  (use \"git add ...\" to include in what will be committed)\n\n\ttest.txt\n\nnothing added to commit but untracked files present (use \"git add\" to track)\ndevops@opsguy:~\/projects\/myrepo$ git add test.txt \ndevops@opsguy:~\/projects\/myrepo$ git commit -m \"first commit\"\n[master (root-commit) cd12dd2] first commit\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 test.txt\n devops@opsguy:~\/projects\/myrepo$ git push -u origin master\nCounting objects: 3, done.\nWriting objects: 100% (3\/3), 206 bytes | 0 bytes\/s, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nremote: \nTo https:\/\/git-codecommit.us-east-1.amazonaws.com\/v1\/repos\/myapp\n * [new branch]      master -&gt; master\nBranch master set up to track remote branch master from origin.\ndevops@opsguy:~\/projects\/myrepo$<\/code><\/pre>\n<h3 id=\"creating-a-branch\">Creating a Branch<\/h3>\n<p>You can create a branch for your repository using &#8220;create-branch&#8221; attribute. For this you must pass the commit id to for the new branch to point to.You can get short hash of commit id&#8217;s using &#8220;git log&#8221; command. An example is shown below.<\/p>\n<pre><code>devops@opsguy:~\/projects\/myrepo$ git log\ncommit cd12dd2b35afc3768a2a025654fa01e6ddb54fa4\nAuthor: devopscube &lt;contact@devopscube.com&gt;\nDate:   Thu Dec 3 18:58:57 2015 +0530\n\n    first commit\ndevops@opsguy:~\/projects\/myrepo$<\/code><\/pre>\n<p>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.<\/p>\n<pre><code>aws codecommit create-branch --repository-name myapp --branch-name newfeature --commit-id cd12dd2b35afc3768a2a025654fa01e6ddb54fa4<\/code><\/pre>\n<h3 id=\"list-all-branches\">List all Branches<\/h3>\n<p>You can list all the branches associated with a repository using &#8220;list-branches&#8221; as shown below.<\/p>\n<pre><code>aws codecommit list-branches --repository-name myapp\n<\/code><\/pre>\n<h3 id=\"rename-a-repository\">Rename a Repository<\/h3>\n<p>A repository can be renamed using &#8220;update-repository-name&#8221; attribute.<\/p>\n<pre><code>aws codecommit update-repository-name --old-name myapp --new-name MyNewApp<\/code><\/pre>\n<h3 id=\"getting-repository-details\">Getting Repository Details<\/h3>\n<p>To get the information about more than one repository, you can run a batch-get-repositories attribute as shown below.<\/p>\n<pre><code>aws codecommit batch-get-repositories --repository-names myapp railsapp<\/code><\/pre>\n<h3 id=\"deleting-a-repository\">Deleting a Repository<\/h3>\n<p>&#8220;delete-repository&#8221; attribute is used with the cli to delete a repository.<\/p>\n<pre><code>aws codecommit delete-repository --repository-name MyNewApp\n<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>devops@opsguy:~\/projects\/myrepo$ aws codecommit delete-repository --repository-name MyNewApp\n{\n    \"repositoryId\": \"2e859c05-06f6-458e-899d-cbc9a589fd33\"\n}\ndevops@opsguy:~\/projects\/myrepo$<\/code><\/pre>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/aws-codecommit-tutorial-beginners\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS Codecommit Tutorial &#8211; Beginners Guide \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/aws-codecommit-tutorial-beginners\/<\/p>\n","protected":false},"author":1,"featured_media":668,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-667","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=667"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/668"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}