Getting Started with AWS EC2: Create Your First EC2 Instance
Tags: aws, ec2instance, webdev, beginners
Published: 2024-02-08 11:47:36

Welcome to this beginner-friendly guide to AWS EC2 (Elastic Compute Cloud). In this video, I’ll briefly overview EC2, its benefits, and why you would use it.  Then in a hands-on tutorial, I’ll walk through how to create a new EC2 instance (using the Windows Amazon Machine Image or AMI), how to connect, and then finally how to terminate the instance.

## What is EC2?
Elastic Cloud Compute, or EC2, is the core service for Compute in Amazon Web Services (AWS).  An EC2 instance is effectively a virtual server that you “**_rent_**,” meaning you only pay for what you use.

## The problem that Amazon Elastic Compute Cloud (EC2) solves: a story
Suppose I'm working for a startup that's creating a website and a mobile app that shows the location of air pumps for tires, my boss, indoors apparently came up with this idea after he had a low tire on his car one day had to drive all over town looking for a gas station that had an air pump because they're a startup they're on a shoestring budget My uncle had an old windows server sitting in his garage so he donated that to the cause it sits at the back of their co-working using to host things one day someone on Reddit mentions their humble little site and it starts to get more traffic the server gets totally overwhelmed and promptly crashes I tell my boss the news and he starts stressing about how they're going to buy a new server to manage the increased website traffic I worked with AWS a little bit in the past and suggested they consider switching to the cloud and also tells him that rather than hosting their application on a single server in AWS instead called an EC2 Instance.

## Overviewing EC2 and its benefits:

Elastic Cloud Compute, or EC2, is the core service for Compute in Amazon Web Services (AWS).  An EC2 instance is effectively a virtual server that you “rent,” meaning that you need it and you only pay for what you use, and in AWS speak these are called instances.

**- Easy to Scale:**
It's easy to scale meaning if you suddenly need 10 extra servers to handle increased traffic it's easy to spin those up and that can even happen automatically with a feature called Auto-Scalling.

**- Reliable:**
EC2 is reliable amazon has billions of dollars of infrastructure around the world and if one of your servers goes down for whatever reason it can automatically be replaced with another one.

**-Use with other services:**
EC2 is one of the foundational AWS services and as such it works seamlessly with all of the other AWS services like networking storage security and so on.

**- Only pay for what you use:**
You only pay for what you use so rather than guessing how many servers you need and buying them and shipping them and setting them up and so on all of that has a lot of upfront costs here you use the EC2 Instance when you need it and you only pay for what you used.

> **Steps to Create an EC2 Instance**
1. Choose AMI
2. Choose Instance Type
3. Configure Instance
4. Add Storage
5. Add Tags
6. Configure Security Group
7. Review

Ready to dive into the world of AWS EC2? Let's start with these step-by-step instructions!  

**1. Create an AWS Account:**

If you don't have an AWS account yet, go to the AWS website and sign up for a new account. You'll need a credit card to complete the registration, but many services, including AWS EC2, offer a free tier for new users to get started.

**2. Access the AWS Management Console:**

Sign in using your AWS credentials at https://console.aws.amazon.com/.

**3. Navigate to EC2:**

In the AWS Management Console, in AWS Services from the drop-down, All Services find EC2 and click on it or type "EC2" in the search bar at the top and select the "EC2" service from the results.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3d2byzv5udkow7rcqge7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qf5nnk1ukft2zrw0npiq.png)
and here on the EC2 dashboard, we're going to launch our first instance the orange button right here launch instance.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xsc2qovgcecjxyv39zr.png)

**4. Choosing an Amazon Machine Image (AMI) for the EC2 instance:**

You'll see the steps enumerated up on the top for the first one of choosing our AMI.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqmb934k8cgfj8v9zjfx.png)
So an AMI or Amazon Machine Image is your basic unit of deployment in EC2 without the AMI you don't have anything as you see at the top it has an operating system installed that'll vary depending on what type you choose.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyrpc9fwfn75bjb6sn0r.png)
There are a lot of aims provided by AWS there are also several available from the community in the marketplace and you can create your own event.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/763vejm39cob7zr4naas.png)
But scrolling down you'll see the options here several available for Linux, Mac, Rat Hat, Windows, and so on a lot of different options here.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6jhs4wm0bttdnzit2j7.png)
The server we're replacing was Windows and this one is a free tier eligible for the Microsoft windows server 2019 base so we're going to go with that over here choose select.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20dbfrv0r368on6dwza7.png)

**5. Choosing an instance type for the EC2 instance:**

Now we need to choose our instance type these types have different combinations of CPUs and memory networking capacity storage and so on and they're grouped into families like you see here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h26j8iaq7g28lfjd5rxv.png)
if you click on the learn more up top this takes you to a page that gives you a lot more detail about what the different families are for
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blt5gcf9r4aj2c3ze5nd.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oe84w6loe2tbgbzbezs7.png)
for our purposes, we want to choose the t2 micro which also is free tier eligible and then we'll come down to the next configure instance details
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z3rd2vtbb230k75vjiry.png)

**6. Configuring instance details for an EC2 instance:**

There's quite a few details on this page here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qullhkwmdbjckyp77dma.png)
settings around pricing and networking and access management and shutdown behavior I'll call out a few things as we go but you'll see there are also really handy tool tips here and some of them also have links where you can learn more so check those out as you're going along
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh6iq5siouoir3702b8l.png)
but starting up here we're just going to create one instance from this AMI you can create multiple instances if you want
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ry0gqgauitk60okxr5mk.png)
moving down the page spot instances have to do with billing and with these you basically specify or bid on the amount that you want to pay these can potentially save you some money but for our purpose, we're going to skip that
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/riptgojkh2gk3s3nv7p1.png)
moving down to the networking section you choose your VPC (Virtual Private Cloud) this is your virtual network that's logically isolated in a part of the AWS
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w1cmfv1lw5hwxhmygtc.png)
you should have one by default like I do here that's what I'm going to go with
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sfqplr8gcwwyhjt33o04.png)
but you could also create a new one from here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iobkhoth4rllugt1o30l.png)
as well then additional details around the subnet IP's hostname DNS hostname and so on once again I'm just going to go with all the defaults and scroll down the placement group and capacity reservation these have to do with how your instance is logically grouped within an availability zone and the capacity you want to hold for it we're going to leave these as defaults as well
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofjq2igw6anpvch3n942.png)
and same goes for this section domain join directory and IMA role these have to do with access and permissions
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ls0zgw8lb9hl18lg3bz4.png)
moving down I do want to call out the shutdown behavior here you'll see that there are two options stop and terminate stop means that the instance is temporarily shut down and that you're going to use it again later when you have an instance that's backed by an elastic block store or EBS volume kind of think of that as the C drive on your regular computer if you stop your instance that EVS volume remains so that it's ready to go next time you start the instance so that it's ready to go next time you start the instance all your data and everything will still be there
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7eqqwb1lf42tocr8039.png)
if you terminate the instance so that's permanent the instance is shut down and your EBS volume is deleted so in most cases you're going to want to go with stop and
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1q2hztlas7uj24wer02s.png)
I'll choose that there are some additional options here we'll go with the defaults as well as the advanced details we'll go with defaults here and then next up we'll add storage.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/auzo1n14lul7bvqvbvbg.png)

**7. Adding storage to an EC2 instance:**

As I mentioned above the EBS or Elastic Block Volume is where you specify that so by default we're getting a purpose state
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vj8vp4g4ite6iaycli1b.png)
the volume type if you want to update some of these other settings you can also add new volumes if you need them
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10o1c73h271fj9hacltu.png)
but we're going to go with it and next to add tags.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05xln5r6io6l1qtbgalb.png)

**8. Adding tags to an EC2 instance:**

Tags are a really useful way to organize and manage your resources so maybe this machine is going to be used for development only as opposed to testing or production so let's add a tag for the environment and our value will be dev or development and we're going to apply this to the instances volumes and network interfaces and say next configure security group.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwf1czs0qvmagpuz1izd.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hmzt6mukp0f1rtwextqv.png)

**9. Configuring security groups for an EC2 instance:**

Security groups are basically your firewall rules that allow or disallow traffic for your instance we're going to create a new one and then you want to add your rules
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7odjoocxb9iujqkkq01.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vxa9m90iwi81mne036u.png)
so for example, if we were hosting a public website here we'd' need to go in and specify HTTP for example access on port 80 and you continue with the same for other rules that you need but I'll get rid of that one as the default rule that was added for us is the remote desktop access on port 3389
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0sp6e3wg2tqn9jor2ack.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73lle883c3sr592utjv2.png)
and the source here with the zeros basically means that we're opening up access to any IP address to RDP into our server generally this is not a good idea that's why you're getting the warning here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nd8f5755goz5vzoajubb.png)
as a best practice, you'll want to restrict this to only known IP addresses but for what we're doing we're going to proceed to review and launch  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pkbtra7re1kx7iz9jsq1.png)

**10. Reviewing and launching an EC2 instance:**

Review all of the details you'll see we're still getting that warning
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afkxq62lm1ks9jlqs745.png)
about having the RDP open to the world again in the real world you would want to change that but everything else looks good here and we're going to say launch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/17ws90u7l9skbu2dpp5u.png)

**11. Creating a key pair for an EC2 instance:**

Next, we're going to be prompted for a key pair and this is required to log into the instance which we're going to do by remote desktop once it's launched we'll go ahead and create a new one
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfjyewfvs33i1dskapgd.png)
For the key pair name, I'll say MyTTTkeypair and then you're going to need to download it I'll add it to the demo folder that I have and say save
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5v5bf9wqh6owukbck5l.png)
and then launch instances
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2zpj96pbeaqyjo7econ.png)
it'll take a minute or two for everything to launch you can view the launch log here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3pwmuinfah8et59fepj.png)
to see what's going on there are some other links you can check here while you're waiting but you can also view instances
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zmnjpyhmmrk9glfdding.png)
this will take you to the list of instances in the ec2 console and you'll see here the status check it's initializing and the instant state is running
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kl5f1k459kj121olntai.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwedh4z2p30acmo4wbnc.png)
you can click on this though and down here below you'll see the details of the instance
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bw3jzo8f20yb831ylcvm.png)
a lot of information here there are also additional tabs security networking storage and so forth so here's where you can manage all the information about your instance you can also do this through the command line interface or the CLI or programmatically as well, now everything looks good here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvx1roaoj5ie8puqe0ky.png)

**12. Connecting to an EC2 instance through Remote Desktop:**

Here I'll select the instance and click on connect
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39r2yo4q5wqt78hggm4o.png)
there are a few different ways to connect to your instance we're going to go with the RDP client remote desktop client here and click on download remote desktop file
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxydq5m9wn2c4kblglnw.png)
this will create a shortcut basically that you just need to click on it's going to connect you to our instance I'll save that on my hard drive
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7vyw9r9ii9v3whe2w1g.png)
I'm putting that up over here I'll just double-click this and we'll say connect here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ddtm1cg73iin5za0fu8x.png)
you're prompted for the administrator password
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m05b4o0efks0yaqf7cue.png)
so you might remember that key pair that we we working with before we needed to go get the password using that
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c94ywp4ahzn8huk8ymd7.png)
so we'll click on get password here and browse for that key pair file
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgnr2k0gqgtnvhccap2o.png)
the dot pem file and open then
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqijfzca6vezu09hv3hp.png)
we need to decrypt the password here
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1p8rr376rn9r5jzaah0.png)
I'll copy that
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hxwghg2cubm4xu4hxgc.png)
and then back to our RDP client I'll paste in the password here and hit ok
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/shh2ekqg9m048wt4cuuc.png)
once again we'll say yes
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/refp9ur7unb8w9la4zod.png)
and here's our Windows server in the cloud and there you go here's where you can do your development work or hosting or whatever you need to do.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwmjpm6u48mh8xns17wy.png)

## **Terminating an EC2 instance:**

If you're following along I want to make sure you go delete your instance
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9v4h9fzinij7on7h64x3.png)
we are using the free tier but no sense in leaving things running out there unnecessarily so back here to your instances go ahead and select this instant state and terminate the instance
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gr8yjt9h3w43nxp5xqj0.png)
remember this is a permanent action your instance will be shut down and your EBS volume or kind of virtual hard drive is going to be deleted as well. so you really want to do this we'll say terminate
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6k5h58meqlr9t1liow2.png)
the instant state is shutting down
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/av2977voc3wg99kec2f3.png)
this might take a minute or two and it will appear here as terminated for a while but it'll eventually drop off your list. 

You can explore deploying applications, hosting websites, running databases, and more. Optimize costs by stopping or terminating instances when not in use. As you continue your journey into the world of AWS, don't forget to discover the other services and capabilities that AWS offers.

So, keep learning, experimenting, and leveraging the power of cloud computing with AWS!🌟