# Continuous Integration & Continuous Deployment on AWS Cloud

## **Prerequisites**

1. Linux and basic commands.
2. General knowledge of the cloud, containerization and the above tools would be good to start. (No issues if you are new to it, you will learn in the way. You got this Champ!)

## What is DevOps?

### Development + Operations :tada:

DevOps is a set of practices that combines software development and IT operations. It aims to shorten the systems development life cycle and provide continuous delivery with high software quality.

### Basics of Deployment&#x20;

Before we start with our projects let's brush up on some basics. I will talk about the steps we undergo to deploy any app or website on webservers (apache tomcat)

1. You have code ready for your application/website created by you or your developer.
2. You will deploy this code (build file) on a Web server (apache tomcat) which will help you access your website through the internet using HTTP/HTTPS protocols
3. For you to place your code in Webserver you need to install it on your Hosted server (EC2). So when your website is up and ready users can access it through domain or hosted servers IP address.
4. You can automate all of the above-listed things with just a single click or even not a click. (Power of DevOps)

{% hint style="success" %}

## Let's Get Started

{% endhint %}

To start we need to have source code you can either use yours if you have one or download/clone my ***GITHUB*** basic project. You can clone/use my [project](https://github.com/N4si/LearnDevOps-on-AWS.git) if you don't have one.

#### Now we are going to launch two ***LINUX*** instances:

1. One Instance to host ***Jenkins***. Jenkins will help us create build files(.war) which we will deploy on Tomcat Server hosted on another EC2 Linux Instance.
2. One to host ***Apache Tomcat Webserve***&#x72;. Tomcat will hold this build file and will help users/clients to access it on the internet using the HTTP protocol.

Do not worry I will also help you install all these tools and software on your Linux EC2 servers. :smile:

{% hint style="info" %}
*\*I believe you have an AWS account with a Free tier. If not! You should have one* [***Free tier***](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank\&all-free-tier.sort-order=asc\&awsf.Free%20Tier%20Types=*all\&awsf.Free%20Tier%20Categories=*all) *today.\**
{% endhint %}

## Let's Launch EC2 instances :cloud:(amazon Linux image)

1. Log into [AWS console](https://aws.amazon.com/console/) & select EC2 service. <img src="/files/aSdOQSnx1UkB6kYXE5KP" alt="" data-size="original">
2. Click on Launch instance
3. You will see a window with Amazon machine images(AMI) full of different operating systems and readymade software or CMS like WordPress but SELECT the ***AMAZON LINUX*** AMI.![](/files/54WgrUwte1rh1aKmwhvL)
4. Choose **t2.micro** *(free tier eligible)*
5. Now go ahead with the default settings >> NO need for Storage >> Add Tags for clear identification: Name \<tab>Jenkins  >> In SECURITY GROUP window open port **8080** for *Jenkins* and port **22** for *SSH* and click "**Review and Launch" >> LAUNCH >**> If you are a new user in new user and don't have any KeyPairs (needed for SSH login) download a KeyPair (name the key "DevOps Key" for reference :thumbsup:) >> Keep the .pem file safe we might need it.
6. ![](/files/ntvFkHflX1FaelwG4Z7d)
7. Your Instance would be launched and you will see a window with an instance in a pending state. ![](/files/xhftvlo3LGRIjaC9azRP)
8. Wait for a few minutes and it will get Running with status checks passed 2/2

ONCE you have an instance you can see all the details about your instance like IP addresses, Security Group attached to it, Instance size, type, and others.

Now we will CONNECT to our LINUX instance we can do it by using PuTTY  (long process) but we will do it using a shorter one provided by the EC2 service follow these small steps and you will enter the Linux world of Terminal :

1. Click on ***"CONNECT" >>*** you will see different options to connect select "EC2 Instance Connect" Click on the Orange Connect button ![](/files/NHoyIdNLH8JcY5FXHhmv)
2. A new tab will open with SHELL and&#x20;
3. Congratulations! You are inside the Jenkins EC2 server. ![](/files/UmiOMSEPgG9911SFI2kT)
4. Here we will Install Jenkins which builds the code and test it and give us build file (.war) which will host on Apache Tomcat.

## Installing JAVA & MAVEN on AMAZON linux instance.

Here you will learn about some Linux command to install, navigate ,edit and create files. (You should know about Linux Commands)

### Installing [JAVA ](https://docs.fedoraproject.org/en-US/quick-docs/installing-java/):tea:

To install Jenkins we need to install Java in your server so run this command.

```
sudo yum install java-1.8.0-openjdk.x86_64
// to change user to root
sudo su - 
cd ~
//edit .bash_profile file 
vi .bash_profile
```

when you run "**`vi .bashprofile`***" command a vim editor window will open and edit ".*&#x62;ash*profile" by providing the java path and add :$*&#x4A;AVA\_HOME as shown in the screenshot.

![](/files/EC3qxER8nQ850wDG94Fy)

to save this file press esc and type "**`:wq`**" this will save your file and close vim editor. Now if you type "**`which java`**" command ![](/files/XvJRztJDQ0WAKUvYDQCU) and you see this output then you have successfully downloaded and placed JAVA file!!

### Install [Maven](#prerequisites) :nerd: <a href="#installmaven" id="installmaven"></a>

\
We need to run maven command in our project to get the build file necessary to host on the Apache webserver so as to download Maven.

Run this command to download [Maven](https://maven.apache.org/download.cgi)

```
wget https://dlcdn.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz
```

This will download maven .tar file untar the file with command:

```
tar xzvf apache-maven-3.8.3-bin.tar.gz
```

Now you have successfully installed Maven and all the necessary files if you run "ls -a" you will see all the maven files

```
cp -r apache-maven-3.8.3 /opt
```

copy the apache-maven-3.8.3 file in /opt file and make changes in .bash\_profile file as shown in the image. (this step is important you will know the reason later)

&#x20;![](/files/Jnhp7Aq21NaPZGPU03xM)&#x20;

(You will see why we did this while creating Jenkins Job)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nasi-chaudari.gitbook.io/devops-on-aws/continuous-integration-and-continuous-deployment-on-aws-cloud.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
