Deployment of Website Using AWS CICD pipeline & Fargate

 



Prerequisite

 We have to have a website in PHP/HTML with a database connection in PHP format. Here we have used HTML for the website designing the form which contains the registration of the student and in the form, we have provided the action of the PHP which contain the basic configuration of the database which is required to store the information.

And most important of having AWS Account to deploy the website and host using AWS Fargate and Github credentials.

Services Used in AWS

  1. AWS CodeCommit: to commit the files of php and others for deployment
  2. AWS CodeBuild: to build the files which are stored in CodeCommit
  3. AWS CodePipeline: to automatedly deploy a website
  4. AWS ECR: repository to store the image
  5. AWS Fargate: to creating a cluster of the image
  6. AWS RDS: for database storage

Following are the steps to implement

As we have made files and also deployed using Ubuntu OS so the all the below command is written in it

1. Now we have deployed on AWS via GitHub credentials

Before deploy create the repository in AWS as shown in figure

After making the repository we have to clone that repository

>> git config –global user.name “<USERNAME>”

>> git config –global user.email “<EMAIL>”

>> git clone <HTTPS URL>

>> cd php

Copy the above mention files in the current directory

>> git add .

>> git commit -m “initial commit”

>> git push

While pushing you will be asked to enter the git credentials which you can generate in IAM Console under your IAM User

Now we have successfully deployed in AWS CodeCommit

Now we have successfully deployed in AWS CodeCommit

2. Create Project in CodeBuild

Now we have to create a project to build

  • Project Configuration
    • >> Project name: php-docker
  • Source
    • >> Source Provider: AWS CodeCommit
    • >> Repository: php
    • >> Reference Type: Branch
    • >> Branch: master
  • Environment
    • >> Environment Image: Managed Image
    • >> Operating system: Ubuntu
    • >> Runtime: Standard
    • >> Image: Choose any
    • >> Image version: by default
    • >> Environment type: Linux
    • >> Check the privilege checkbox
    • >> Service Role: New service role
  • Buildspec
    • >> Build Specification: use a buildspec file

Now click on Create Build Project

Successfully created build project

We have to add 2 more policies to IAM role which we have created during Build Project and it will give access to RDS and ECR Registry,

  1. AmazonRDSFullAccess
  2. AmazonEC2ContainerRegistryFullAccess

3. Image in ECR

Now we have to create the repository in ECR and named it php

Created ECR Repository

4. Create cluster in AWS Fargate

Now we will create the cluster using AWS Fargate which will create a serverless-platform on which we can deploy our website.

>> Open ECS console and click on Get Started

Step1: Container and Task

Container Definition

>> Select Custom and click on configure

>> Container Name: Docker-Website

>> Image: <Copy URL of Image from ECR>

            >> Memory Limit: Soft Limit – 512

>> Port Mapping: 80

>> Click on Update

Click on Next

Step 2: Service

>> LoadBalancer Type: Application Load Balancer

Click on Next

Step 3: Cluster

>> Cluster Name: Docker-Website-Cluster

Click on Next and review and Click on Create

Created Fargate
Fargate will also create VPC
Fargate also create LoadBalancer

5. Create a RDS Database

 Click on Create Database

  • Choose a database creation method: Standard create
    • >> Engine Option: MySQL
    • >>Template: Free-tier
  • Setting
    • >> DB Instance Identifier: phpfargate
    • >> Master User Name: admin
    • >> Master Password: ******
    • >> Confirm Password: ******
  • DB Instance Type
    • >> Burstable Classes: db.t2.micro
  • Connectivity
    • >> VPC: Choose VPC which we have created in Cluster

And leave rest as by default and click on Create Database

 Created RDS Instance

>> Copy EndPoint of RDS in $host parameter in db_config.php file

6. Create CodePipeline

Step 1: Choose a Pipeline Setting

>> Pipeline Name: Webapp-Pipeline

>> Service role: New service role

Click on Next

Step 2: Add Source Stage

>> Source Provider: AWS CodeCommit

>> Repository Name: php

>> Branch Name: master

Click on Next

 Step 3: Add Build Stage

>> Build Provider: AWS CodeBuild

>> Project Name: php-docker

Click on Next

>>Skip Deploy stage and click on Next

>> Review and Click on Create Pipeline

Created CodePipeline

Output

Now we can access our website from the cluster

>> Cluster à Task à Select Task and Under Network Section Copy Public IP Address

On copying IP address in web browser the following page will appear


Comments

Popular posts from this blog

Install terraform on ubuntu and Create EC2 instance on AWS using terraform script

Deploy Django website using AWS Elastic Beanstalk CLI in windows