DEV Community

Cover image for Launching an AWS EC2 Instance
Rahimah Sulayman
Rahimah Sulayman

Posted on

Launching an AWS EC2 Instance

What is an AWS EC2?

Elastic Compute Cloud (EC2) is a virtual server that you rent in AWS, which means you only use it when you need it and only pay for what you use. This is called "instance" in AWS.

Why should you use EC2?

The core objective of using AWS EC2 (Elastic Compute Cloud) is to provide resizable, on-demand computing power in the cloud.

Instead of buying a physical server, putting it in a room, and plugging it in, EC2 allows you to "rent" a virtual slice of a powerful data center in seconds.

Here are the primary objectives broken down:

  • Scalability(Elasticity).
    If your website gets a sudden spike in traffic, you can launch 10 more instances instantly. It's easy to spin this up and it can even happen automatically using a feature called auto scaling.

  • Reliability and Global reach
    If one of your servers goes down for whatever reason, it can be automatically replaced with another one. This is because Amazon has billions of dollars of infrastructure all over the world. To host your application closer to your users, you can launch an EC2 instance in London, Tokyo, or Virginia with one click to reduce latency (lag) for users in those areas.

  • Use with other services.
    It is one of AWS foundational services and as such it works seamlessly with the other AWS services such as networking, security, storage, and so on.

  • Cost Optimization
    You Only pay for what you use.
    So rather than guessing how many servers you need, buying them, shipping them to your office, setting them up, maintaining them and so on, which has a lot of "Upfront" cost, you just use instance when you need it and only pay for that use.

  • Full Control (Root Access)
    Unlike "Managed" services where AWS handles everything, EC2 gives you the keys to the kingdom.
    To have absolute control over the operating system (Ubuntu, Windows, etc.), software stack, and security settings. As you saw in your screenshot, you have a terminal where you can run sudo commands and install exactly what you need.

Now let me walk you through how to create and connect an EC2.

Step 1:
On the Console Home page, search for EC2 in the search bar.

searchec2
Step 2:
On the Launch instance section,select Launch Instance.

launch

Step 3:
Give it a Name.

name

Step 4:
On the Application and OS Images(Amazon Machine Image), select the image type you want. The AMI is basically a template that says here's the operating system and preinstalled applications that I want on the machine.
Below there are options for each operating system.

AMI

copyimage

options

Notice you can browse for more AMIs on the right from AWS, the marketplace and the community. So there's no shortage of options.

marketplace

Step 5:
Based on the AMI you select, you'll have different options for your Instance type. It has the CPU, memory and so on with different pricing. There are lots of options here too.
If you want to find out more about the Instance type, click on the info.
Notice you can create more than one instance at a time with the same settings we provided earlier on, using the "Number of instances" option.

info

Step 6:
Enter Key pair name.
If you want to connect to your Instance, you'll need a Key pair. Select Create new key pair.

createnewkey

keyname

newkey

Step 7:
Go with the defaults on Network settings.

defaultnetwork

Step 8:
Launch the instance.

The Launch log of everything we created appears, click Launch instance at the bottom right.

launch

waiting
Step 9:
Select Connect to Instance.

connect

Step 9:
On the Connect section, scroll down and select Connect.

connect

connect

establish

Notice the server name here

nameappears

Step 10:

Don't leave things running if you don't need them so make sure you terminate your server, otherwise you bill will increase. You can terminate it in the CloudShell by running some commands, but notice that the account verification is still in process. This is beyond the scope of this post.

terminate

Alternatively, you can click the "Services" icon (the grid) next to the AWS logo in the top left, and select EC2. Or just type "EC2" into the search bar.

EC2

It takes you back to the EC2 Dashboard, select Instances, then select the Instance you want to delete.

Instances

Notice Instance state is running.

running

Step 11:
Click on the Instance state and select terminate(delete)instance.

select

Step 12:
Confirm terminate.

confirm

Notice Instance state is shutting down.

shutting
Now it is terminated.

terminated

Note the difference between Terminated and Stopped: "Stopping" is like turning off a computer (you can turn it back on later). "Terminating" is like throwing the computer in a shredder.

Things to keep in mind

  • Billing: You stop being charged for the instance hours as soon as the state changes to shutting-down or terminated.

  • Irreversibility: Once you terminate an instance, it is permanent and cannot be recovered.

  • Data Loss: By default, the root EBS volume attached to the instance will be deleted along with it.

  • Cleanup: The instance will remain visible in your console for about an hour after termination before disappearing.

In Summary, "Mastering the AWS CLI and EC2 isn't just about launching servers, it's about understanding how to build scalable, reliable infrastructure from the ground up. This post shows how to navigate the AWS ecosystem, troubleshoot environment-specific hurdles, and maintain a clean, cost-effective cloud footprint.

Top comments (0)