AWS EC2 Introduction

AWS EC2 (Elastic Compute Cloud) is a popular cloud computing service provided by Amazon Web Services (AWS). It allows users to quickly provision and configure virtual servers, known as instances, in the cloud. EC2 offers elastic scalability, a wide range of instance types, pay-as-you-go pricing, integration with the AWS ecosystem, and advanced security features. With EC2, businesses can easily scale resources, choose the right instance type, pay for what they use, and benefit from seamless integration with other AWS services. EC2 simplifies infrastructure management and enabling faster application deployment

This article will show the steps needed to create an EC2 instance that you can use to host and run an application.

Creating AWS Account

First of all you will need to create a root user from the AWS site https://aws.amazon.com. You will need a card in order to create the account, however you won't be charged unless you use a service that has a cost. For the purpose of this article, we will use a free instance image. At the moment of writing this post, this is what a free tier EC2 image offers:

Free tier: In your first year includes 750 hours of t2.micro (or t3.micro in the Regions in which t2.micro is unavailable) instance usage on free tier AMIs per month, 30 GiB of EBS storage, 2 million IOs, 1 GB of snapshots, and 100 GB of bandwidth to the internet.

Creating EC2 instance

Once you have already created your account and login. You will get into the console page. From here, follow below steps:

  1. Go to services -> Services
  2. CLick on "Launch an Instance" button
  3. Provide instance name (i.e. WebServer)
  4. Choose "Amazon Linux" as OS image
  5. Choose a free tier instance type - t2.micro (1 cpu, 1GB menory, 8GB storage Volume)
  6. Click on Create new key pair and provide name (linux1), type as asa and format as .pen. Finally click on create key pair. (Although you can create your instance without key pair, it’s recommended to create one due to security concerns)
  7. Once key pair is created, you can choose it from drop down list in Key Pair settings section
  8. From network settings, choose the ip addresses from where you want to allow ssh connections or 0.0.0.0/0 to allow ssh connection from anywhere (as long as key file is provided)
  9. Allow http and https traffic from internet as we want this instance to run a web server that can be reached by any browser
  10. Choose 8GB of storage
  11. Finally click on "Launch Instance" button

Then you will be directed to the instances dashboard. Once the value on Instance state shows as Running, you will be able to connect to your new EC2 instance.

Instance Connection

From EC2 instances page, click the id under "Instance ID" column. Then click on the "Connect" button. You will see a page with the instructions to stablish a ssh connection to your EC2 machine. You can even copy an example ssh command, so you can run this one as such, you just need to make sure to be located on the directory where you have the .pem file.

[] $ ssh -i "linux1.pem" ec2-user@{your-vm-public-DNS}

If everything goes fine, you should see an Amazon Linux welcome prompto, and you will see that you are login as ec2-user. From ec2-user, you will be able to work as root by running

[] $ sudo su -