Photo by Christian Wiediger on Unsplash

The industrial revolution has brought us a degree of wealth that would have seemed unimaginable to our ancestors and it’s all thanks to the phenomenon known as economy of scale.

IKEA factories can pump out a desks much faster than an individual building them by hand. In the same sense, we can obtain more computational resources (i.e. a server with better specs) at the same cost by using the infrastructure of tech giants instead of purchasing the hardware ourselves.

The current world leaders in cloud computing are Amazon Web Services (AWS) proceeded by Microsoft’s Azure then the Google Cloud Platform.

In this article, we will create a AWS EC2 instance in the cloud.


If you haven’t already, you’re going to want to install the AWS Command Line Interface (CLI).

The installation should have already added C:\Program Files\Amazon\AWSCLI\bin\ to your PATH variable. Try running aws --version, if it returns a value, your installation was successful. If you run into problems try opening a new shell.

Configure The AWS CLI

AWS Access Key ID and AWS Secret Access Key

These are your account credentials, protect them at all costs. If someone were to get their hands on them, they could use computing resources and run your bill up thousands of dollars.

Default region name

If you select us-east-2 as the default region then all the commands will make API calls to the data centers in that region unless specified otherwise.

If you don’t know the name to your region, you can list them by running the following line.

Default output format

The output of aws commands can be in json (default), text, or table format.

Security Group

In essence, a security group is a virtual firewall. You can set rules to limit access to your instance.

Be sure to copy the GroupID somewhere because we’ll need it when we go to create the instance.

The value of the CIDR range corresponds with the range of IP addresses that are allows to access your instance. A value of all 0s means that any computer connected to the Internet can access your instance. Theoretically, if someone were to get hold of your SSH key, they could get into your VM. For better security, replace the with the range of IP addresses you'll use to connect to your instance.

At minimum, we need to open port 22 (SSH protocol) so that you can connect to your instance.

Key Pair

The proceeding line creates a 2048-bit RSA key pair with the specified name. The aws ec2 command stores the public key and outputs the private key for you to save to a file. The .pem file will be passed in as an argument when you go to connect to your instance.

In a Windows Command prompt, use double quotes instead of single quotes.

Note: Make sure you are using a Windows Command Prompt and not Powershell as you may run into issues.

Amazon Machine Image

If you’ve had any prior experience working with virtual machines, you know that they require an image. An EC2 instance is no different. When creating a EC2 instance from the command line, we specify the operating system using the amazon machine image (AMI) ID.

In this tutorial, we’ll be using the Amazon Linux 2 AMI however there are actually quite a few available in the free tier.

To get the image ID corresponding to the Amazon Linux 2 AMI, run the proceeding code.

To get the command that retrieves the latest amazon machine image for a specific distribution, visit the following link.

Instance Type

You can have the latest version of windows at home but if it’s running on a decade old computer chances are that you’re slamming your keyboard wondering why it’s so slow.

All this to say, the operating system is completely independent of the underlying hardware that runs it. In the context of AWS, every type of an instance has its own set of specs. These specs include CPUs, RAM, networking capacity and storage.

t2.micro is the only instance type available in the free tier.


Elastic Compute Cloud or EC2 provides scalable computing capacity in the Amazon Web Services (AWS) cloud.

You can list your instances withaws ec2 describe-instances.

It can take several minutes to create the instance. Once the it’s up and running, you can use the following command to get the public IP address.

Finally, we can connect to our EC2 instance over the Internet.

Where the user is the default user name associated with the AMI you used to launch the instance. For an Amazon Linux AMI, it is ec2-user.

If you’re on Windows, you’ll need to use putty. Putty doesn’t accept keys in .pem format so we’re going to have to use puttygen to convert the key into .ppk format.

Open puttygen and click load.

By default, puttygen will only look for files that end in .ppk, make sure you’re looking for all files.

After loading the .pem file into puttygen, hit Save private key. Save the key in .ppk format.

Now under the SSH tab in putty, select the .ppk file.

Now you’re ready to connect to your instance using putty.

Once you’re done with your VM. You can enter exit to exit out of your session.

Amazon won’t charge usage for a stopped instance. However, they do charge you for Amazon EBS volume usage.

Run the following code to terminate your EC2 instance.

Data Science | Data Engineer @ Interset | LinkedIn:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store