DEV Community

Cover image for Getting Started with AWS EC2: Create Your First EC2 Instance
Syed Mustafa Hassan
Syed Mustafa Hassan

Posted on

Getting Started with AWS EC2: Create Your First EC2 Instance

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
Image description
and here on the EC2 dashboard, we're going to launch our first instance the orange button right here launch instance.
Image description

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
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
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
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
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

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
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
Image description
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

6. Configuring instance details for an EC2 instance:

There's quite a few details on this page here
Image description
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
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
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
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
you should have one by default like I do here that's what I'm going to go with
Image description
but you could also create a new one from here
Image description
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
and same goes for this section domain join directory and IMA role these have to do with access and permissions
Image description
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
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
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

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
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
but we're going to go with it and next to add tags.
Image description

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
Image description

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
Image description
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
Image description
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
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

10. Reviewing and launching an EC2 instance:

Review all of the details you'll see we're still getting that warning
Image description
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

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
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
and then launch instances
Image description
it'll take a minute or two for everything to launch you can view the launch log here
Image description
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
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
Image description
you can click on this though and down here below you'll see the details of the instance
Image description
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

12. Connecting to an EC2 instance through Remote Desktop:

Here I'll select the instance and click on connect
Image description
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
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
I'm putting that up over here I'll just double-click this and we'll say connect here
Image description
you're prompted for the administrator password
Image description
so you might remember that key pair that we we working with before we needed to go get the password using that
Image description
so we'll click on get password here and browse for that key pair file
Image description
the dot pem file and open then
Image description
we need to decrypt the password here
Image description
I'll copy that
Image description
and then back to our RDP client I'll paste in the password here and hit ok
Image description
once again we'll say yes
Image description
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

Terminating an EC2 instance:

If you're following along I want to make sure you go delete your instance
Image description
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
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
the instant state is shutting down
Image description
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!🌟

Top comments (0)