Continuous Deployment : Using AWS Code Commit, AWS Code Deploy and Jenkins (Part 1)

While we build scalable, highly available and fault tolerant systems on Amazon Web Services, it is important to look out AWS deployment tools which can handle system and application level deployment ensuring consistency, predictability and integrity across multiple environments. This leads to continuous and faster deployment, lower failure and error rates and quick recovery.
Continuous Integration is a software development practice where continuous changes and updates in code base are integrated and verified by an automated build scripts using various tools.
Continuous Deployment is also a software development practice whose role is to automatically deploy the code to the specified server and application folder once the code is been integrated successfully.
Continuous Delivery is an end-to-end process for taking a functional requirement from concept to production as fast as is necessary to meet business needs. It depends on frequent deployments of small units of code rather than infrequent deployments of big releases. Successful continuous delivery also depends on DevOps—deep collaboration between development and operational IT functions
Here I ‘m going to describe about some AWS service and popular automation tool Jenkins to build a highly available, highly scalable, fault tolerant and zero down time deployment processes application infrastructure in AWS Cloud.
Scenario:
Suppose we have setup two different environments (Staging and Production) and the entire server are architecture on Amazon Web Services. And it was featured with AWS Auto Scaling service which used to help scale the servers depending on the metrics and policies we specified. And all your instances are behind a load balancer.
Requirements:
  • Need to implement a tool for Continuous Integration.
  • Keep the downtime to bare minimum during releases process.
  • Ability to revert the changes from a particular developer with ease
  • Automatically deploy the latest code commits directly to staging servers.
  • After passing the QA process staging server move to production.
Though the above challenges are not the blockers but we have to bring up a technique that must save high amount of time and make our life easy with automating all the process from CI to CD. We choose to use Jenkins as CI tool and AWS Code Deploy as a CD tool. This post walks you through the steps to set up CodeDeploy, Jenkins and AWS CodeCommit to support simple continuous integration (CI) and Continuous Delivery (CD) scenarios.  AWS CodeDeploy deployments with instances that are behind an Elastic Load Balancer or in an Auto Scaling group.
In this scenario, the developer push the change to AWS CodeCommit hosted repository and have the change trigger a build in Jenkins. And deploy the code to servers by using AWS CodeDepoly. For the walkthrough, we will run the Jenkins server on an Amazon Linux Instance and configure the Git repository hosted by AWS CodeCommit.
Step 1:  Configure AWS CodeCommit Git repository
 AWS CodeCommit is a secure, highly scalable, managed source control service that hosts private Git repositories. AWS CodeCommit eliminates the need for you to manage your own source control system or worry about scaling its infrastructure. You can use AWS 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.
Set Up IAM Permissions
AWS CodeCommit uses IAM permissions to control access to the Git repositories.
Need to create an IAM user, an IAM role, and a managed policy. Then attach the managed policy to the IAM user and the IAM role, granting both the user and role the permissions to push and pull changes to and from the Git repository hosted by AWS CodeCommit. And then need to associate the IAM role with the Amazon EC2 instance you launch to run Jenkins. (Jenkins uses the permissions granted by the IAM role to access the Git repositories.)
Creating IAM Users and Role for an AWS Service (AWS Management Console)
  • To create one or more IAM users with the AWS Management Console
  • Sign in to the Identity and Access Management (IAM) console at https://console.aws.amazon.com/iam/.
  • In the navigation pane, choose Users and then choose Create New Users.
  • Create an IAM user. Save the access key ID and the secret access key for the new user.
  • Attach the managed policy named AWSCodeCommitFullAccess to the IAM user you created.
  • In the navigation pane of the IAM console, click Roles, and then click Create New Role.
  • Create an Amazon EC2 service role named CodeCommitRole and attach the managed policy (AWSCodeCommitFullAccess) to it.
Create an AWS CodeCommit Repository
 To create the AWS CodeCommit repository (console)
  • Open the AWS CodeCommit console at https://console.aws.amazon.com/codecommit.
  • On the welcome page, choose Get Started Now. (If a Dashboard page appears instead of the welcome page, choose Create new repository.)
  • On the Create new repository page, in the Repository name box, type MyDemoRepo.
  • In the Description box, type description of that repository.
  • Choose Create repository to create an empty AWS CodeCommit repository named MyDemoRepo.
codecommit-create-repository

Set Up Local Development Environment
 Install Git and the AWS CLI on your workstation.
Linux or Mac:
$ sudo apt-get install git-all
Install the AWS CLI Using the Bundled Installer (Linux, OS X, or Unix)
After you install the AWS CLI, you must configure it using your IAM user credentials that  created in previous step.
aws configure
Enter the AWS access key and AWS secret access key for the IAM user you created; enter us-east-1 for the region name; and enter json for the output format.
AWS Access Key ID [None]: Type your target AWS access key ID here, and then press Enter
AWS Secret Access Key [None]: Type your target AWS secret access key here, and then press Enter
Default region name [None]: Type us-east-1 here, and then press Enter
Default output format [None]: Type json here, and then press Enter
Configure Git to use your IAM credentials and an HTTP path to access the repositories hosted by AWS CodeCommit.
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.useHttpPath true
Set your user name and email address.
git config --global user.name "Your Name"
git config --global user.email "Your Email Address"
Create a local copy of the repository.
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/DemoRepo
This will clone the empty AWS Code Commit repository to you local development environment. Now you can copy the existing source code or create new source file to this folder and make a first commit. For more info:  https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started.html

Comments

Popular posts from this blog

Datastax Error : Cannot start node if snitch's data center (dc1) differs from previous data center (dc2)

Datastax Error : Cassandra - Saved cluster name Test Cluster != configured name

Configure Nagios plugin " check_logfiles " for scanning log file

Popular posts from this blog

Datastax Error : Cannot start node if snitch's data center (dc1) differs from previous data center (dc2)

Datastax Error : Cassandra - Saved cluster name Test Cluster != configured name

Configure Nagios plugin " check_logfiles " for scanning log file