Thursday, January 20, 2022

Deploy Source Code in EC2 Machine using AWS codecommit, codedeploy and codepipeline.

1) CodeCommit –

A fully-managed source control service that hosts secure Git-based repositories. CodeCommit to create a repository to store the application and deployment codes.


2) CodeBuild –

A fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy, on a dynamically created build server. This solution uses CodeBuild to build and test the code, which we deploy later.


3) CodeDeploy –

A fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers.


4) CodePipeline –

A fully managed continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates. This solution uses CodePipeline to create an end-to-end pipeline that fetches the application code from CodeCommit, builds and tests using CodeBuild, and finally deploys using CodeDeploy.



Let's Begin .........

Step 1) IAM USER for Git

- Policy - "CodeCommitFullAccess"
- Genrate HTTPS Git credentials for AWS Code-commit authentication


Step 2) Code Commit

- Create Repo
- Make Branch


Step 3) Update The Source Code on The Repository

- Download Default Html Code
- https://s3.amazonaws.com/aws-codedeploy-us-east-1/samples/latest/SampleApp_Linux.zip


Step 4) Create IAM EC2 Role for AWS Code Deploy and also Attach with EC2

- Role_Name - EC2-Role-for-AWS-Code-Deploy
- Policy - "AmazonEC2RoleforAWSCodeDeploy"


Step 5) Lanuch EC2 Instance (LinuxAMI2) and Attach with EC2

- Attach IAM Role  (EC2-Role-for-AWS-Code-Deploy)
- Install CodeDeploy Agent Package by Following

#!/bin/bash
sudo yum -y update
sudo yum install -y ruby
sudo yum install -y aws-cli
cd /home/ec2-user
aws s3 cp s3://aws-codedeploy-us-east-2/latest/install . --region us-east-2
sudo chmod +x ./install
sudo ./install auto

- Connect EC2 Via SSH
- Check Status of CodeDeploy Agent Package (sudo service codedeploy-agent status)
- In Security Group Allow Port 80 for all
- Write The Tag & Value (Tag:Name , Value:EC2-WEB-SERVER)


Step 6) Create IAM Role For CodeDeploy Service.

- Create IAM Role
- Policy - "AWSCodeDeployRole"


Step 7) Configure CodeDeploy

- Create Application
- Create Deployment Group
- Add EC2 Tag & Value


Step 8) Configure Pipeline

- Run pipeline
- Build is optional (you can skip it)



No comments:

Post a Comment

testing