DEV Community

loading...

[AWS] 2. EC2

Nina Hwang
👩🏻‍💻 황채영 🐣 Junior Backend Developer
Updated on ・4 min read

When I first learned programming in a coding bootcamp, I did 2 projects with other students including those who were taking the frontend course. Back then I knew nothing about AWS, so I had to run the following command whenever my teammates requested.

Alt Text

Plus, I had to leave my laptop in the class so that the teammates were able to test their code without me.
Suppose you are working at a mobile application company like Facebook but all you have as a physical server is a single laptop. What if you spill coffee on it? What if there’s a blackout? It would be a total disaster. Your clients would be mad and might never use your service again. That’s why you need either a proper physical server or a virtual server. This post is about EC2, which is a virtual server that you can use to run applications in AWS.

What is EC2

Amazon EC2(Amazon Elastic Compute Cloud) provide scalable computing capacity in AWS Cloud. It eliminates your need to invest in hardware, so you can develop and deploy applications faster. Amazon EC2 provides many features including:

  • Renting virtual machines
  • Storing data on virtual drives
  • Distributing loads across machines
  • Scaling service(ASG)

How to launch a EC2 Instance

An instance is a virtual server in the AWS cloud. With Amazon EC2, you can set up and configure the operating system and applications that run on your instance.

Launch Types

On-demand Instance

Once you launch an on-demand instance, you’ll be charged for what you actually used. Since there’s no long term commitment it has the highest cost. If you need an instance for a short period like when you do EC2 tutorial, this would be the perfect choice.

Reserved Instance

If it is anticipated that you’re going to use EC2 instance for a long period, you can get up to 75% discount compared to on-demand instance by using reserved instance. Reservation period can be 1 or 3 years. There are 2 types of reserved instance - convertible reserved instance and scheduled reserved instance. With a scheduled reserved instance, you can schedule when the instance runs.

Spot Instance

If your priority is cost-efficiency and you don’t need a stable instance, you can use spot instances. Spot instances offer up to 90% of discount compared to on-demand instances. It is the most cost-efficient, but if your max price is less than the current spot price, you are going to lose it. So it is not the best decision if you do critical jobs with a spot instance or use it as a database.

Dedicated Host

It is a physical EC2 server which is dedicated for you. You can get full control of EC2 instance placement.

Dedicated Instance

Similar with dedicated hosts, with dedicated instance, you will get a dedicated hardware. But you may share the hardware with other instances in same account. And you have no control over instance placement.

EC2 Hands-on

Launching EC2 Tutorial

Alt Text
By clicking the blue 'Launch Instance' button, you can launch an instance. On the left side, you can see 'Reserved Instances' and 'Dedicated Hosts'.
Alt Text
Alt Text
There are so many types of EC2. You should carefully select the option that suits your needs. I chose 'Amazon Linux 2 AMI (HVM), SSD Volume Type' and 't2.micro' because it is free tier eligible.
Alt Text
Alt Text
Here you can set details of the instance. You can make it as a spot instance or a dedicated host/instance. If you chose neither of them, your instance will be on-demand.
Alt Text
You can set its name.
Alt Text
Alt Text
Alt Text
After configuring security settings(I am going to write another post about it), the instance is ready to run.

Launching EC2 Tutorial

Alt Text
Change current directory where you stored your EC2 pem file.
Run the following command(chmod 0400 <your-pem-file>) so that you can access to EC2 server.
Alt Text
You should use your own pem file name and IPv4 Public IP.

Discussion (0)