AWS DevOps Real-Time Deployment - Dev → Pre-PROD → Production

AWS DevOps Real-Time Deployment - Dev → Pre-PROD → Production

Completion Steps →

  1. fetch a code from GitHub by git clone

  2. Setup code commit repository on AWS

  3. push code to code commit using AWS CLI

  4. setup aws code-build for building code

  5. setup S3 bucket for code storage

  6. setup code deployment for the deployment of code stored in AWS S3

  7. setup an EC2 in which you deployed your application

  8. Setting Up AWS CodeDeploy Agent on Ubuntu EC2

  9. create the deployment group and deploy the application

  10. Setup code pipeline to automate the whole process

Step 1 →

  1. git clone

above command pulls your application code to your local that is needed to be pushed in the aws code commit

step 2 →Setup code commit

  1. go to the AWS console search aws code commit and create a demo repository

2. provide necessary permission to aws code commit to use it with aws cli which needs to create an IAM user having the permission of aws code commit

3. search IAM and click on Create user

4. click next and create a user

5. now you have to permit your user to code commit

6 . click on user →security credentials →scroll down for HTTPS Git credentials for AWS CodeCommit →click on generate credentials and download csv.credentials file

7. you also need to attach a policy called “AWSCodeCommitPowerUser

go to permissions and then click on attach policies directly search for the above policy and click on add

your code commit repository is set next move to step

Step 3 → push code to code commit using AWS CLI

  1. clone your code commit URL go to your terminal and run git clone <copied url>

  2. it will ask you for a username and password → give it to your code commit credentials that you generated

3. now you have to push all the cloned code of the project repository to your code commit repository by commands

  1. cd demo

  2. git clone

  3. git add.

  4. git commit -m ”new commit”

  5. git push

pushed code in a code commit

Step 3 → Setup aws code-build for building code

  1. go to the AWS console and search for AWS code build

  2. click on the Create Project option

  3. give a name to your project “demo project”

  4. on the repo option click on demo and branch to master

  5. for OS choose Ubuntu,runtime to standard and image to the latest version

  6. build spec file → It is a file that tells the code build what steps are needed when you building the code we have a build spec file in the code commit so the “click on use a build spec file” option

  7. click on create build project option and keep everything as it is

8. Now click on start build option

now you need to store this code in s3 which is further used by code deployment for deployment

step 5 →setup S3 bucket for code storage

  1. go to the console and search for s3 and create a bucket

  2. bucket name should be unique globally

3. go to code build and click on edit → artefact →change no artefact to s3 and choose a bucket created in above step

4. and choose a zip file for storage

5. click on update artefacts and build again the same project with this extra step of artifacts

6. after building you will see that your code is stored in an s3 bucket

now we have to move to step no.6

Step 6 →setup code deployment for deployment of code stored in aws S3 to an EC2

  1. go to console and search for aws code deploy and click on create application option

select ec2 in the dropdown menu

Step 7 → setup an EC2 in which the application will run or be deployed by code deploy

  1. go to ec2 and launch the Ubuntu machine

create an aws ec2-service role

having the following permission which helps ec2 to communicate with code deploy

2. attach that role to your ec2 →actions →security →modify iam role

create an aws code_deploy_service_role

this role needs to be attached on code deployment to allow it to make contact with ec2 and s3

Step 8 →Setting Up AWS CodeDeploy Agent on Ubuntu EC2

To deploy your app to EC2, CodeDeploy needs an agent that deploys the code on your EC2.

So let’s set it up.

Create a shell script with the below contents and run it

  1. connect to your ec2 and run the following commands

  2. sudo su

  3. apt update

  4. vim

copy and paste the following code to your file

# This installs the CodeDeploy agent and its prerequisites on Ubuntu 22.04.
sudo apt-get update
sudo apt-get install ruby-full ruby-webrick wget -y
cd /tmp
mkdir codedeploy-agent_1.3.2-1902_ubuntu22 
dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22 
sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control 
dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/ 
sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb
systemctl list-units --type=service | grep codedeploy 
sudo service codedeploy-agent status

5. press →esc + : +wq →for exit

6. to run this file use the command →bash

you have the following output

your code deploy agent is running

let’s move to the next step

Step 9 →create the deployment group and deploy the application

  1. go to your code deploy and create a deployment group

copy the srn of aws code_deploy_service_role or created above

2. choose in place in deployment type

3. select ec2 instances →name →choose your ec2 in which code deploy agent is running

4. untick on enable load balancing option and never on install aws code deploy agent

and click on the Create Deployment option you will see the following page

click on the Create Deployment option following page appears

5. select the above options and paste the path of your build code that is stored in s3 just go to s3 choose a folder and copy the s3 URL

and then click on Create Deployment after a few seconds

your application is successfully deployed

now go to your ec2 and click on your public IP you will see your application is running

congrats you are a DevOps and cloud engineer both at the same time

Step 10 → Setup code pipeline to automate the whole process

  1. go to your code pipeline and create a pipeline

2. select pipeline type = V2

click on new service role →next step

3. choose source = code commit



choose aws code pipeline(this options immediatley triggerd pipeline whenever there is a new commit in a repo)

4. choose aws code build

project name =demobuild →single build →next step

5. choose aws code deploy

aplication name = demo app

deployment group=demo_dep


6. review and pipeline and start it

7. for checking if it triggers or not whenever i commit make some changes in file and now the result is the following image

If you find this article helpful then you can buy me a coffee.

Follow for more stories like this 😊/ GitHub.