Creating your first EC2 Instance in just 10 steps
A Beginner's Guide to Cloud Computing
Introduction
Creating your first EC2 instance might seem like a difficult task, but it's actually pretty easy once you get the hang of it. In this article, we'll walk through creating your very first EC2 instance. But wait, what does "EC2" mean? EC2 stands for Elastic Compute Cloud, it is one of Amazon Web Services' (AWS) core services. Understanding how to configure and manage your EC2 instances is a fundamental and essential skill to excel in cloud computing. Without further talk, lets' get into it!
Prerequisites
An active AWS account
Basic Understanding of Cloud Concepts such as amazon machine images (AMI), security groups, key pairs etc.
A stable Internet Connection and Supported Web Browser
What is an EC2 Instance?
An EC2 instance is a virtual server in the cloud that allows you to run your applications, host websites and perform computing tasks with physical hardware or even the need for one. Instances come with various configurations including size, images, security, and level of permissions, all of which can be configured based on your specific needs.
Creating Your Instance: Step by Step
Before we jump into the nitty-gritty of creating an EC2 instance, let's briefly discuss what it is and why it's essential in cloud computing.
Sign into your AWS account
If you don't have an AWS account yet, you can create one for free (guide to create a free tier account). Once you're logged in, you'll be greeted by the AWS Management Console.
Navigate to EC2
In the AWS Management Console, you can find EC2 under the "Compute" section. Click on "EC2" to enter the EC2 dashboard.
Launch an Instance
To create an EC2 instance, click the "Launch Instance" button. You'll be guided through a series of steps, including choosing an Amazon Machine Image (AMI), selecting an instance type, configuring instance details, adding storage, and configuring security groups.
AMI
Choose an AMI, you can select an AMI that suits your needs. AMIs are pre-configured templates for various operating systems and software configurations. Choose one that aligns with your project requirements. For this tutorial, we'll go with "ubuntu".
Enter "first-instance" as Instance Name.
Instance Type
Select the hardware configuration of your EC2 instance. Each instance type has different CPU, memory, and network performance characteristics. Choose one that meets your application's requirements. For this tutorial, we'll go with "t2.micro".
Key Pairs
During the setup process, you'll need to create or select an existing key pair. This key pair allows you to securely connect to your EC2 instance using SSH (Secure Shell). Be sure to save the private key securely.
Private key files come in 2 formats:
-PEM keys can be used on Unix, Linux, and macOS systems with OpenSSH or other compatible SSH clients.
-PPK is primarily used with PuTTY, a popular SSH client for Windows.
The steps to create a key pair:
-Click "Create new key pair"
-Enter the key pair name as "first-masterkey"
-Leave the key pair type as "RSA"
-Choose ".ppk" as private key file format
-Click "Create key pair"
Note*: key pairs can only be used* ONCE!
Network Settings
Click "Edit" to configure Network settings
We'll be configuring the following settings:
-VPC
-Subnet
-Firewall (Security Groups)
The steps:
-Leave VPC as "default"
-Choose a Subnet in any availability zone of your choice
-Enter "first-instance-firewall" as the Security group name
Your Network Settings should look like this at the end:
Review and Launch
All done now!
Review your instance configuration, and if everything looks good, click the "Launch Instance" button.
There you have it, You've successfully launched your instance, but the journey's not over yet as you'll need to allow traffic to your instance. There are still some configurations to be made, but don't worry, the journey's almost over.
Security Groups
You'll need to configure your security groups to allow incoming and outgoing traffic as per your requirements. Security groups act as virtual firewalls for your EC2 instances.
Navigate back to the Main Instances List screen to view your instance. For your instance to work, you'll need to wait for your Instance State to show "Running" and Status check "2/2 checks passed". You may need to refresh the page to see the changes as shown below:
On to configuring security group:
-Select the instance you created.
-Click on the Security tab.
-Click on the Security Groups link.
Click on "Edit inbound rules" button
-Click the "Add rule" button
-Choose Type as "HTTP"
-Choose Source as "Anywhere-IPv4"
-Save rules
Connect to your Instance
Now that your EC2 instance is up and running, you can connect to it using SSH (if you're using a Linux-based AMI). We will be installing "Apache Web Server" to test that the instance is working correctly.
-Select your instance and Click "Connect"
Ensure that the EC2 Instance Connect tab is selected and click "Connect"
You will be greeted with this page
Install Apache with the following command
sudo apt update && sudo apt install apache2 && sudo systemctl status apache2
The Apache service should show "active(running)"
Navigate back to the Instances list, and click on the "copy icon" NOT "open address". "Open address" treats the IP address as a secure link (https:) and the security group configured was for "HTTP".
Open a new tab in your browser and paste the Public IP address in the address bar as such
http://<your-public-ipv4-address>
If everything is configured well and working right, you should be greeted with the "Apache2 Default Page"
There are other ways to connect to your instance (view my blog on it) such as SSH or Remote Desktop Protocol (RDP) for Windows instances. Use the private key you downloaded earlier to access your instance securely if need be.
Conclusion
You've successfully launched your first (or not) EC2 instance! Congratulations. In this article, we learnt the basics of setting up an EC2 instance. There's still so many ways to configure instances and so many things you can do with them.
Remember, learning anything, not just cloud computing, is a journey and each step matters. As you continue to explore more AWS services, you'll begin to see the unique features of each and with time, you'll be able to integrate them and use what you need, when you need them.
You can always use this article as sort of a refresher whenever you need to create another instance.