In this article of our AWS journey series, we will be studying about AWS EC2 service. We will look into:
What is EC2?
Why we need EC2?
What are the types of EC2 instances?
What is the concept of regions and availability zones?
How to create an EC2 instance using AWS console?
Installing Jenkins on our EC2 instance and accessing from outside world.
Let's get started.
What is EC2?
EC2 stands for Elastic Cloud Compute.
"Elastic" refers to the ability to easily and dynamically scale computing resources up or down based on demand.
"Cloud" in this context refers to the cloud computing model, where computing resources (such as servers, storage, databases) are delivered over the internet on a pay-as-you-go basis. Users can access and manage these resources remotely, without the need for physical hardware ownership or maintenance.
"Compute" pertains to the processing power and capacity required for running applications, performing calculations, and processing data. In the case of AWS EC2, it provides virtual servers (compute instances) that users can use to run applications, host websites, and perform various computing tasks.
We will see how to create an AWS EC2 instance using the AWS console in this blog only.
Why we need EC2?
If you are on the private cloud, it involves significant challenges. It requires the procurement, setup, and maintenance of physical hardware, often leading to high upfront costs and complex infrastructure management. Scaling resources can be slow and costly.
On the other hand, Amazon EC2 simplifies this process by offering a public cloud solution. With EC2, businesses can access virtual servers in minutes without the need for physical hardware.
It provides flexibility to scale resources up or down based on demand, eliminating the complexity of hardware management. EC2's pay-as-you-go model also ensures cost-effectiveness, as users only pay for the computing capacity they use.
What are the types of EC2 instances?
AWS offers various types of EC2 instances. Here are some commonly used ones:
General Purpose Instances (e.g., "t3," "t4g," "t3a"): Balanced compute, memory, and networking resources.
Compute Optimized Instances (e.g., "c6g," "c5," "c4"): High-performance processors, ideal for compute-bound applications. Best suited for compute-intensive workloads like scientific modeling and batch processing.
Memory Optimized Instances (e.g., "r6g," "r5," "r4"): Designed for memory-intensive applications and databases. Suitable for in-memory databases, real-time big data analytics, and other memory-bound workloads.
Storage Optimized Instances (e.g., "i3," "i3en," "h1"): Optimized for high, low-latency storage performance. Suitable for data-intensive workloads like large databases and distributed file systems.
Accelerated Computing Instances (e.g., "p4," "p3," "f1"): Equipped with specialized hardware accelerators (GPUs or FPGAs). Ideal for graphics-intensive applications, machine learning, and high-performance computing.
What is the concept of regions and availability zones?
Regions
In AWS, regions and availability zones are fundamental concepts related to the global infrastructure that supports AWS services.
A region is a geographical area where AWS has data centers, called Availability Zones. Each region is entirely independent and is designed to be isolated from other regions to provide fault tolerance.
Users can choose a specific region to host their resources, allowing them to position data and applications close to their end-users for low-latency access.
Example: AWS regions include US East (N. Virginia), EU (Ireland), Asia Pacific (Mumbai), and more.
Availability Zones (AZs)
An Availability Zone is essentially a data center or a group of data centers within a region.
Availability Zones provide fault tolerance and high availability. Deploying resources across multiple Availability Zones helps ensure that if one zone goes down, applications and data can still be accessed from another zone.
Example: A region may consist of multiple Availability Zones, such as us-east-1a, us-east-1b, and so on.
How to create an EC2 instance using AWS console?
Log-in to your AWS account as a root user.
Search for "EC2" service and select that and you will be able to see an interface like this which is known as EC2 dashboard.
Click on "Instances(running)" option. Then click on "Launch instances".
You will see an interface as shown below.
Under Names and tags, give a name to your EC2 instance. Let us say 'demo-instance' for now.
Under Application and OS Images (Amazon Machine Image), select Ubuntu.
Under Instance type, select t2.micro, which will be auto-selected.
Under key pair (login), click on create new key pair. You see something like this.
Give a name to your key pair and click on Create key pair.
This is the thin we will be using to connect to our instance remotely.
Leave other settings as it is and click on Launch instance.
You will see that your instance will be created.
Go to the instance dashboard and you will see the EC2 instance running after some time.
In the screenshot above, click on the Instance ID and you will land onto a page similar to the one shown in screenshot below.
Copy the Public IPv4 address, because we will use it accessing our instance remotely.
Now if you are a windows user, I will show you how to access your EC2 instance.
Download MobaXterm.
After successfully downloading MobaXterm, you will see an interface as shown below.
In this click on Session, in the top left side and you will see this type of interface.
Choose the SSH option.
In Remote host, enter the Public IPv4 address we copied.
In username, enter ubuntu.
Click on Advanced SSH settings. Tick the Use private key option, and select the .pem file that we downloaded while creating the key pair.
Follow this screenshot to avoid any confusion.
Finally, click on OK.
You will be inside your EC2 instance as shown in the screenshot below.
If you are facing any issues in connecting to your EC2 instance, watch this video.
Note that if you are use macOS or Linux, then follow this video to connect to your EC2 instance.
So that was all about how to connect to an EC2 instance remotely from a windows machine.
Installing Jenkins on our EC2 instance and accessing from outside world
Let us see how to install Jenkins on our EC2 instance and access it from outside world.
Follow these commands:
sudo apt update
First we need to install Java.
sudo apt install openjdk-11-jdk
Check if Java is installed or not.
java --version
Install Jenkins,
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Check if Jenkins is up and running,
sudo systemctl status jenkins
Let us access Jenkins from your local machine.
In your browser, paste that Public IPv4 address followed by :8080.
However, your application is running but still you will not be able to access it. Because your application by default is not accessible to the external world.
To sort this problem,
Go to the instance > security > security groups > edit inbound rules > add rule.
In type, select Custom TCP.
In Port range, enter 8080.
In source, select anywhere IPv4.
Click on Save rules.
Now again go to your browser and refresh. You will be able to access the Jenkins application.
Outro
Congratulations, we just did a deep dive into AWS EC2.
We saw how to create an EC2 instance, how to connect to it remotely, how to install an application on it and access it from the outside world.
Stay tuned for more such amazing articles on AWS concepts and various services.