AWS Code Commit , Code Deploy and Code Pipeline creation step by step
Step:1 Prerequisites
- Download and install Git on you local system(Linux and Windows)
- Configure GIT on your system
- git config --global user.email <your email id>
- git config --global user.name "your name"
- Create New AWS IAM user (Or use existing admin user)
a. Attach IAM policy "AWScodecommitFullAccess"
b. Attach IAM policy "AWScodePipelineFullAccess"
c. Security Credentials -->> HTTPS Git Credentials -->>Generate and Save the credentials
- Create Service Role for CodeDeploy
a. Create IAM role for CodeDeploy service
b. Attach existing IAM policy "AWSCodeDeployRole"
- Create IAM Role for Ec2 to download logs from S3
a. Create IAM role for EC2 service to attach "AttachS3readonlyAccess"policy
Step:2 Configure CodeCommit Respository
- Go to CodeCommit Service (Use North Virginia Region )
- Create new code repository with name "Demo-project"
- Copy the Clone URL >>Clone HTTPS
- Clone Git Repository locally
- Git clone <URL>
- Provide username/Password (This should create empty repository)
- Download Sample Application
- Download application locally
- Unzip and move all files and folders inside your local repository "Demo-project" directory
- Change your CMD to Demo-Project
- git status
- Git add -A
- Git commit -m "Added sample application files"
- Git push
Step:3 Launch EC2 instance to Host Application
- Launch EC2 instance with below requirements
- AMI: Amazon Linux 2
- Instance Type: T2 Micro
- VPC: Default
- IAM Role: Role that we created in Step #1
- In Advance option , Paste the below user data to install CodeDeploy Agent
#!/bin/bash
yum -y update
yum install -y ruby
yum install -y aws-cli
cd /home/ec2-user
aws s3 cp s3://aws-codedeploy-ap-south-1/latest/install . --region ap-south-1
chmod +X ./install
./install auto
- Tags: Key: Name, Value: Demo
- Security Group: Open Port no # 22 and 80 for my IP or Internet
- SSH keypair: use existing keypair
- Launch
Step:4 Create Application in Code Deploy
- Go to CodeDeploy service
- Create New Application
- Name:Demo
- Compute Platform: Ec2/On-premises
- Create Application
- Deployment Groups
- Name: Demo-Group
- Deployment Type:In-place Deployment
- Environment configuration :
- Amazon EC2 Instances
- Enter the Key=Name and Value=Demo (That you created while launching EC2 instance)
- Deployment Configurtion
- Select CodeDeployDefault.OneAtaTime
Step:5 Create CodePipeLine
- Go to AWS CodePipeline service
- Create Pipeline
- Name:Demo-Pipeline
- Service Role: New Service Role
- Artifact Store: Default
- Add Source Stage
- Source Provider : AWS CodeCommit
- Repository: Select your Repository "Demo-project"
- Branch: Select Master branch
- Detection Option: Select CloudWatch Events
- Add Build stage -->SKIP
- Add Deploy Stage
- Deploy Provider: AWS CodeDeploy
- Application Name: Demo (This you had created in previous Step #4)
- Deployment Group: Demo-Group (This you had created in previous Step #4)