AWS Code Commit and Code Deploy and Code Pipeline creation step by step

Step:1 Prerequisites

 

  1. Download and install Git on you local system(Linux and Windows)
  1. Configure GIT on your system
    1. git config --global user.email   (git config --global user.email cloudsunilpatel@gmail.com)
    2. git config --global user.name "your name"  (git config --global user.name "Sunil Kumar Patel")

 

  1. Create New AWS IAM user Or use existing admin user (User Name:SunilCode)

    a.   Attach IAM policy "AWScodecommitFullAccess"

    b.   Attach IAM policy "AWScodePipelineFullAccess"

    c.   Security Credentials  -->> HTTPS Git Credentials -->>Generate and Save the credentials file

 

  1. Create Service Role for CodeDeploy  (Role Name:AWSCodeDeployRole)

  a. Create IAM role for CodeDeploy service

  b. Attach existing IAM policy "AWSCodeDeployRole"

 

  1. Create IAM Role for Ec2 to download logs from S3  (Role Name:Name:AmazonS3readonlyAccess)

  a. Create IAM role for EC2 service to attach "AmazonS3readonlyAccess" policy 

 

 

Step:2 Configure CodeCommit Respository

 

  1. Go to CodeCommit Service (Use North Virginia Region )
    1. Create new code repository with name "Demo-project"
    1. Copy the Clone URL >>Clone HTTPS (https://git-codecommit.ap-south-1.amazonaws.com/v1/repos/Demo-project)

 

  1. Clone Git Repository locally
    1. Git clone
    2. Provide username/Password (This should create empty repository)

This is assuming your authenticating with IAM roles. If you are add the default AWSCodeCommitReadOnly policy then you can be sure that you can rule out IAM policies. The supplied commands:
git config --global credential.helper '!aws codecommit credential-helper $@'

git config --global credential.UseHttpPath true

  1. Download Sample Application
    1. Download application locally
    2. Unzip and move all files and folders inside your local repository "Demo-project" directory
    3. Change your CMD to Demo-Project
    4. git status
    5. Git add -A
    6. Git commit -m "Added sample application files"
    7. Git push

 

 

 

Step:3 Launch EC2 instance to Host Application

 

  1. Launch EC2 instance with below requirements
    1. AMI: Amazon Linux 2
    2. Instance Type: T2 Micro
    3. VPC: Default
    1. IAM Role: Role that we created in Step #1
    1. In Advance option , Paste the below user data to install CodeDeploy Agent

#!/bin/bash

sudo yum update -y

sudo yum install ruby -y

sudo yum install  awscli -y

cd /home/ec2-user

aws s3 cp s3://aws-codedeploy-ap-south-1/latest/install . --region ap-south-1

chmod +X ./install

./install auto

#!/bin/bash

sudo apt update

sudo apt install ruby

sudo apt install awscli

cd /home/ubuntu

aws s3 cp s3://aws-codedeploy-ap-south-1/latest/install . --region ap-south-1

chmod +X ./install

./install auto

 

  1. Tags: Key: Name, Value: Demo
  2. Security Group: Open Port no # 22 and 80 for my IP or Internet
  1. SSH keypair: use existing keypair
  2. Launch

 

 

Step:4 Create Application in Code Deploy

 

  1. Go to CodeDeploy service
  2. Create New Application
    1. Name:Demo
    1. Compute Platform: Ec2/On-premises
    1. Create Application
  1. Deployment Groups
    1. Name: Demo-Group
    2. Deployment Type:In-place Deployment
    3. Environment configuration :
      1. Amazon EC2 Instances
      1. Enter the Key=Name and Value=Demo (That you created while launching EC2 instance)
  1. Deployment Configurtion
    1. Select CodeDeployDefault.OneAtaTime

 

 

Step:5 Create CodePipeLine

 

  1. Go to AWS CodePipeline service
  2. Create Pipeline
    1. Name:Demo-Pipeline
    2. Service Role: New Service Role
    1. Artifact Store:  Default
  1. Add Source Stage
    1. Source Provider : AWS CodeCommit
    1. Repository: Select your Repository "Demo-project"
    1. Branch: Select Master branch
    2. Detection Option: Select CloudWatch Events
  1. Add Build stage -->SKIP
  2. Add Deploy Stage
    1. Deploy Provider: AWS CodeDeploy
    2. Application Name: Demo (This you had created in previous Step #4)
    1. Deployment Group: Demo-Group (This you had created in previous Step #4)