Launching An AWS EC2 Instance & Installing Jenkins On It

Author: Ayush Maggo


This technical blog will walk you through the process of creating and configuring an EC2 instance, followed by step-by-step instructions to install Jenkins. By leveraging the capabilities of Amazon Web Services (AWS), you can enable efficient continuous integration and delivery for your applications in the cloud. Explore the potential of AWS EC2 and unlock the benefits of Jenkins to enhance your development and deployment workflows.

What is EC2?

EC2 refers to Elastic Compute Cloud. It is an elastic cloud computing service that provides virtual servers, known as instances, to run applications. EC2 allows easy provisioning, configuring, and management of instances. It provides flexibility, scalability, and integration with other AWS services for building and managing cloud-based infrastructure. It enables efficient deployments, and monitoring of applications in the cloud.

Why is it important?
  • Secure, resizable cloud compute with flexible infrastructure for dynamic needs.
  • Access reliable and scalable infrastructure on demand, with the added capability to scale capacity within minutes, backed by a robust 99.99% availability SLA commitment, ensuring uninterrupted performance.
  • Optimize performance and cost with flexible options, including AWS Graviton-based instances, Amazon EC2 Spot instances, and AWS Savings Plans.
  • It operates on a “Pay-as-you-go” method.
Types of EC2 instance:
  1. General Purpose Instances – They are the most widely used instances in AWS, offering balanced computation, memory, and networking resources. General Purpose Instances are mostly used in gaming servers, small databases, and personal projects.

T3, M5, and M6g instances are types of general purpose instances.

  1. Compute Optimized Instances – Compute-optimized instances are suitable for applications that require significant computation. This type of instance is good for application servers, gaming servers, and web applications.

C5, C6g, and C6gd are types of compute-optimized instances.

  1. Memory Optimized Instances – These instances are ideal for memory-instance applications that require high RAM capacity to process large datasets at a fast speed. Good examples of memory-intensive instances include Big Data analytics.

R5, R6g, and X1 are types of memory optimized instances.

  1. Storage Optimized Instances – Storage optimized instances are used for workloads that have high storage requirements that require fast read and write operations on disk. Data warehousing applications, and high-frequency online transaction processing systems are the good examples of workloads that are suited for storage-optimized instances.

D2, H1, I3, I3en are the storage optimized instances types.

  1. Accelerated Computing Instances – Accelerated Computing instances utilize additional hardware accelerators/co-processors such as Graphics Processing Units (GPUs) and Field Programmable Gate Arrays (FPGAs) to accelerate processing. Examples of accelerated computing instances include graphics applications, game streaming, and application streaming.

P3, P2, Inf1, G3, G4, F1 are types of accelerated computing instances.

Depending on the application, we choose the required type of EC2 instance.

What is Jenkins?

Jenkins is an open-source automation tool written in Java with plugins designed for continuous integration and continuous delivery. It is used to continuously build and test software projects, facilitating the seamless integration of changes made by developers and ensuring users have access to up-to-date builds.

Launching an EC2 Instance
  • Search for the EC2 service, and after clicking on EC2, proceed to click on Launch Instance.
  • Provide a name to the instance.
  • Select the Amazon Machine Image (AMI), it contains the operating system, application server, and applications. I am using the “ubuntu” AMI.
  • Select an Instance type that suits your computing requirements. I opted for t2.micro.
  • Enter the number of instances you want.
  • Now, choose a key pair, or you can also create a new key pair.
  • You can either leave the Network setting as it is, or you have the option to choose the VPC and subnets according to your preference.
  • You can either leave the configure storage setting as it is, or choose according to your preference.
  • Review the instance details and click Launch to start the instance.
  • The process may take a few minutes. Once the instance is successfully launched you are able to see it.
Connecting to the EC2 instance from the terminal
  • Open the terminal on your local machine.
  • Now switch to the directory where your key pair file is saved.
  • Grant the permission to the key pair file.
chmod 600 first-key-pair.pem
  • Now, we need to connect to our instance using the Public IP address using the command below.
ssh -i <key_pair_file_name> <AMI_name> @<Public IP>

Run the above command in the path where your key pair file is located.

ssh -i first-key-pair.pem ubuntu@
  • Now switch to the root user using the sudo su command.
  • Execute the apt update command to update the packages.
Installing and Configuring Jenkins on the Instance
  • For Jenkins, we need to install Java Development Kit (JDK) on instance, as Jenkins requires Java to run.
  • Run the below command to install JDK.
apt install openjdk-11-jdk
  • Validate the installation by running java –version
  • Now, let’s install Jenkins using the commands below.
curl -fsSL | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
  • Enable Jenkins using the below command.
systemctl enable jenkins
  • Start Jenkins using the below command.
systemctl start jenkins
  • Run below command to check the status of Jenkins
systemctl status jenkins
  • Open AWS EC2 > SELECT EC2 > select security group > inbound rules > edit inbound rules > add rule > CUSTOM TCP > PORT = 8080 > Source > IPv4 Anywhere > Click on Save rule.
  • Access the Jenkins web interface using the Public IP or DNS name of your EC2 instance (I use Public IP address), along with the default port 8080.

By default, Jenkins runs on port 8080.

  • Run the cat /var/lib/jenkins/secrets/initialAdminPassword command in your terminal to retrieve the initial administrator password from the EC2 instance’s file system and unlock the Jenkins.
  • Now, finally, the Jenkins console is accessible and up and running.
  • Now, you can use Jenkins.

In this blog, we explored the concept of AWS EC2 instance and learned how to create an instance and install Jenkins on it. EC2 provides a scalable and flexible computing environment in the cloud, while Jenkins empowers automation and enables continuous integration. By combining the power of EC2 instance and Jenkins, developers can streamline their application deployment workflows and enhance the software development process in the AWS cloud.

Happy Learning!

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.