logo
How to host a basic web app project on AWS Cloud using CI/CD (DevOps)

How to host a basic web app project on AWS Cloud using CI/CD (DevOps)

This project is about hosting a website on a web server on the AWS platform using CI/CD pipeline {Continuous Integration/ Continuous Deployment}.

Published Jan 15, 2024

Hello readers!!!
This project is about hosting a website on a web server on the AWS platform using CI/CD pipeline {Continuous Integration/ Continuous Deployment}.
In this project, we are going to use different AWS services -
AWS code commit, code artifact, code build, code deploy, code pipeline, S3 storage, IAM service, CloudWatch etc.
To make this project there are some pre-requirements —
  • GitHub Account {To create an account, visit this link}
  • AWS Platform Account {To create an account, visit this link}
  • Git installation in your system {To download git visit this link}
    For deploying our webapp, we need a server. For that we will make two instances, one for production level & one for Testing purpose before going live on our main production server.
    So let’s get started……
    Now, search ec2 instance and click on instances. After that click on launch instance. Do not give any name now.


    Now click on create a new key pair and save into your system. Now come down and allow https/http both networks. Increases number of instances from 1 to 2. No click on launch instance.


    Now select any one of instance and go to tags. Their click on manage tags and in —
    Key — Env
    Value — Testing
    Now click on save. Perform exact steps for other instance too to give tag name. give that value name Prod.



    Now go to setting icon shown in below image and after scrolling down, in tag columns select Env too. After doing this you ill get to know that which instance belong to which category either testing or production.


    Now select any one instance say testing, then click on connect.


    Now run below commands to setup our code deploy agent into both servers.
    sudo yum update -y
    sudo yum install -y ruby wget
    wget https://aws-codedeploy-ap-south-1.s3.ap-south1.amazonaws.com/latest/install
    chmod +x ./install
    sudo ./install auto
    sudo service codedeploy-agent status

    After running all these commands into testing server, run these exact same commands into production server too.
    Next step is, search IAM in aws search bar and come into role section. Here
    Click on create role >> select aws service >> select use case “EC2”>>click on next>>search codedeploy >> select “AmazonEc2roleforawscodedeploy” & “Awscodedeployfullaccess” >>click on next.
    Then give that role a name. Here i have gave “ec2codedeployrole”.


    Your policy is ready..

    Now again click on create role >> select aws service >> select use case as “codedeploy” >>click on next >> it automatically select iam role. Click on next. Give this role a name, Here i have give “Codedeploytoec2”.


    Now go to your ec2 instances and select any one instance >> go to action >> go to security >> Modify IAM role >> select the role “ec2codedeployrole” which we have created just above.
    Repeat same for other instance too.


    Now go to Code deploy section & go to application >> create application.
    Give application a name, here i have give webappproject. Select compute platform as EC2/on premises. Now click on create application.


    Now go inside of application & click on create deployment group.

    Now gave deployment group name “testingenvec2group”, select service role which we have created above “Codedeploytoec2”. In enviourment configuration select amazon ec2 instance, there in key select “Env” and value “testing”.
    In agent configuration select never as we already have configured agent already. Uncheck load balancer. No click on create deployment group. Your group is ready.






    Now make another deployment group, name it prodgroup and select service role which we have created above “Codedeploytoec2”. In enviourment configuration select amazon ec2 instance, there in key select “Env” and value “testing”.
    In agent configuration select never as we already have configured agent already. Uncheck load balancer. No click on create deployment group. Your group is ready.



    Now go to code pipeline and click on create pipeline.
    give pipeline name >> In advance section select custom location and in s3 bucket give your bucket name >> click on next.
    Add source code stage — —
    give Source provider- “AWS code commit” >> repository name — “myrepo” >> Branch name — “master” >> click on next.
    Add build stage — -
    Build provider — AWS code build >> project name — cicdproject >>Click on next.
    Add Deploy stage —
    Deploy provider — Aws codedeploy >> Application name — webappproject >> deployment group — testingenvec2group >> click on next.
    Review —
    click on create pipeline.






    Our pipeline is ready, but wait a minute we have not added our prod group then how our webapp will install on final server. For that first stop pipeline by clicking on stop.

    Now click on edit and scroll down and add stage after deploy and give that stage name proddeploy.
    After this, in proddeploy, click on add action group >> action name — prodaction >> Action provider — AWs codedeploy >> Input Artifact — Source artifact >> Application name — webappproject >> Deployment group — prodgroup>> Done.




    Now in between to make sure everything is running good in testing server, then it go for live production server, we need to make a quality assuring team stage, which will check everything. After their approval, our web app will go for production deployment.
    So click on add stage in between deploy or proddeploy. Give that stage name QATSTAGE. Add action group >> Action name — qataction >> Action provider >> Manual approval.




    That’s it. Our pipeline is ready. Click on save.

    Now then you push final code of your webapp, our pipeline will automatically get started and push our code to our server.
  • All code file you can find here--
  • aaryangupta/ci-cd-project-over-aws (github.com)
    Tip: — If found error then you can just restart ec2 instance, it will solve your error mostly.


    Here i have hosted a tic tac toe game in my server.

    Thanks for reading !!!!!!!!!!!
  • For any issue you face or troubleshooting fell free to reach out to me —
    AARYAN GUPTA | LinkedIn