DEV Community

Yuvraj Thapa Chhetri
Yuvraj Thapa Chhetri

Posted on

From GitHub to Production: Streamlining Deployment with CI/CD , LB and AS

Introduction

Recently, I deployed an application to AWS Cloud using GitHub, utilizing an automated CI/CD pipeline on AWS. In this blog, I focused on using AWS Code Pipeline to ensure that whenever a developer pushes code to GitHub, it is automatically deployed to the server. I have outlined the step-by-step process to set this up, making it easier for teams to streamline their deployment workflows.

Here is architecture for deployment application using AWS Code Pipeline
Image description

Why You Should Implement Application Deployment in Launch Templates ?
In today's digital landscape, businesses need to deploy applications quickly and seamlessly. Utilizing a CI/CD (Continuous Integration/Continuous Deployment) pipeline allows us to automate the process from development to production. Here are some key benefits:

  1. Speed and Efficiency: CI/CD accelerates the development and deployment process, enabling developers to release code faster.

  2. Quality Assurance: Automated testing helps identify bugs and issues early, improving the overall quality of the application.

  3. Scalability: With auto-scaling features, applications can adjust resources based on demand, optimizing resource utilization and controlling costs.

  4. Reliability: Load balancing efficiently distributes traffic, minimizing downtime and enhancing user experience.

  5. Cost-effectiveness: Automated processes and resource scaling lead to lower operational costs, as you only use resources as needed.

Now, Let's start with practical

Image description

First, we have to create Launch Template

Go to launch template under Instances and click on create launch template

  • Launch Template Name: write your launch template name
  • Template version description: v1
  • In OS and Images tab: Click on quick start and select your OS according to your requirement
  • In instances type: Select Free tire [t2.micro] or you can select your requirement
  • Key pair: Create your key pair and keep it securely
  • Network setting: leave as execute
  • Firewall (Security Groups):Select create security group

---Security Group Name: write security group name
---Description: allow ssh and http (s)
---VPC: you can select your own VPC or leave as execute

  • Click on add security groups rule and add three security rules:

---Type: ssh / http /https
---Source type: Anywhere  

  • Expand Advance detail In IAM instance profile: Select new IAM Profile and create role

Image description

  • After select create role:

----Select trusted entity: AWS Service
----Use Case: EC2 and then click on Next button
----Add permission tab: search codedeploy and select
AmazonEC2RoleforAWSCodeDeploy

Image description

  • In role detail tab: write role name and description then click on create role.

Image description

  • After create role come back advanced details under launch template and select your role

Image description

  • Scroll down and search for User data and write some script:

Image description

NOTE: Change the underline text according to your region

  • Now, Create launch template

After launch template select Auto scaling Groups

Image description

Auto scaling configuration

---Name: write your ASG name
---Launch Template: Select your template

  • Version: Latest (1)
    Image description

  • Click on next

  • Under Network setting

---Select VPC: select default VPC or select your own VPC
---Availability Zones and subnets: Select minimum two subnets like 1a
and 1b

Image description

  • Click Next
  • Under Load balancing tab:

Image description

  • Select Attach a new load balancer

---Load balancer type: Network Load Balancer
---Load balancer name: write your LB name
---Load balancer scheme: Internet-facing

Image description

  • Under Listeners and routing:

---Protocol: TCP
---Port: 80
---Default routing (forward to): create a target group
---New target group name: Give your TG name

Image description

  • Under Group Size

---Desired capacity: 0
---Min desired capacity: 0
---Max desired capacity: 0

  • Select target tracking scaling policy

---Scaling policy name: Target tracking policy
---Metric type: Average CPU utilization
---Target Value: 50

Image description

  • Then click on create button and you can see there is no instances and desired capacity.

Image description

Now, go to CodeDeploy

Image description

  • Select Application under deploy tab and create application

Image description

  • Under Application Configuration:

---Application name: write your application name
---Compute platform: Select EC2/On-premises

Image description

  • Now, after create application click on create deployment group

Image description

  • Now, go back IAM dashboard and create role for deployment group

Image description

  • In trusted entity type > select AWS service

  • In use case > select CodeDeploy

Image description

  • Enter the role name

Image description

  • Select View role

Image description

  • then copy the ARN link of role

Image description

  • Paste your ARN in service role tab under Deployment group

Image description

  • Now Under Environment Configuration tab

  • Mark on Amazon EC2 Auto scaling Groups

  • Select your ASG

Image description

  • In Deployment Setting

---Deployment Configuration : Select CodeDeployDefault.OneAtAtTime

Image description

  • In Load Balancer Tab
  • Mark on Enable Load balancing
  • Select your target group of Application LB or Network LB
  • Now, Go to Pipelines under pipelines side nav bar

Image description

  • In pipeline setting

---Pipeline name: write your name
---Pipeline type : Select v2
---Execution mode: select Queued (pipeline type V2 required)
---Service role: Select New service role

  • Role name automatically appear in your role name box

Image description

  • Under source Tab

---Source Provider: GitHub (Version 2)]

  • Click on connect to GitHub

Image description

  • Create Connection

---Connection name: Give your connection name

  • Then click on connect to GitHub button

Image description

  • Click on Install new app

Image description

  • Now, Login github

Image description

  • Mark on Only select repositories

  • Select your repositories

  • Then click on install

Image description

  • now, click on connect

Image description

  • ensure your repository name and default Branch is correct

Image description

  • Under Trigger Tab

  • Select No filter

Image description

  • Skip Build Stage

Image description

Now, Configuration Deploy

Deploy provider: AWS CodeDeploy
Region: Asia Pacific (Singapore)
Application name: select your Application name
Deployment group: select your Deployment group

Image description

  • Click on deploy button

  • Then, your code will be automatically deploying
    .
    If there will error given as a picture below So, we have to configure auto scaling desired capacity.

Image description

  • Search EC2 > select auto scaling group

Image description

  • select your ASG and change desired capacity value given as a picture below

Image description

  • again, go to CodePipeline and retry stage

Image description

  • After deploy go to load balancer dashboard and copy DNS name and paste it any browser your application will be working.

Image description

Your application is ready now

Finally , we successfully deploy application from github to cloud. Deploying applications through a CI/CD pipeline has become an essential practice in today’s competitive market. This approach not only enhances your development process but also provides better service to your end-users.

Top comments (0)