Getting Started with AWS (PART-II)

Chaitanya Varma Manthena
DevOps Engineering on Cloud
12 min readDec 28, 2022
Getting started with Amazon web services.

This article will teach you about the commands to interact between the servers and to understand basic networking concepts, you will get started with AWS to provision Ubuntu-based virtual machines. These Virtual Machines will be used in the subsequent sections to understand the basic concepts related to AWS.

continuation to the PART-I

👨🏽‍💻🧑🏻‍💻For more ARTICLES, FOLLOW📍DevOps Engineering on Cloud

Let’s get started.

Login into AWS EC2 Instance using Key Pair

As part of getting started with AWS, To log in to an EC2 instance, a respective keypair is needed. So when you create a key pair while creating an instance, a .pem file will be downloaded to your downloads folder on your PC. Using that .pem file you should be able to connect to that EC2 instance.

Downloads directory in Windows

On top of the .pem file, you also need to have either Public DNS or Public IP to connect to the EC2 instance. You get the Public IP and Public DNS details by selecting the instance that you created in the instances dashboard.

🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link

In case you have used the browser in your windows system to create the key pair and EC2 instance the .pem file will most likely be downloaded to the downloads folder, At times you might have configured the downloads folder to some other location if you couldn't find the .pem file under the downloads folder, you need to figure out the location which you have used for downloads and go to that location to find the .pem file using this .pem file and the public DNS you should be able to connect to that EC2 instance.

EC2 instance Dashboard

It is better to understand that the Public IP4 DNS is derived from the Public IPv4 address.

Now open Windows Powershell. Powershell already has Open SSH you should be able to use open ssh in PowerShell to connect to your EC2 instance.

The SSH command which is used to connect to your EC2 instance is as follows,

ssh -i .\Downlaods\gsdemo1.pem ubuntu@ec2–54–167–87–77.compute-1.amazonaws.com

Here -i is used to specify the identity file which is the .pem file so you should give the path to the .pem file.

Ubuntu is the name of the user, and

ec2–54–167–87–77.compute.amazonaws.com is the IPv4 DNS of the instance you want to log in.

The IPv4 DNS changes every time you stop and restart an instance so you should replace the IPv4 DNS while connecting from time to time.

If you log into your instance for the first time, it'll prompt you to type yes/no. Type yes and you'll be logged into your instance.

Connecting to the EC2 instance

You won’t be able to log in to the instance if the .pem file doesn't have the appropriate permissions. If the permissions are 777 then the output when you use ssh to log in will be as follows,

Unprotected private key file

One way to change the permission for the .pem file is to use chmod command which is as follows,

chmod 400 gsdemo1.pem

Validate whether the permissions are changed using the following command

ls -ltr gsdemo1.pem
Changing pem file permissions

Now after changing the permissions try to log in using the following command

ssh -i gsdemo1.pem ubuntu@ec2-54-167-87-77.compute-1.amazonaws.com
Logging into the EC2 instance

Now you will be able to connect to your EC2 instance, If you are not sure about the SSH command you can verify it from the AWS EC2 management console.

Select your instance and click on connect to get additional details related to the connection.

EC2 instance Dashboard

The instance user name can be found in the EC2 instance Connect

EC2 instance connect

Click on SSH client where you can find the example SSH command and it'll be prompted to change the permissions for the pem file to either 600 or 400.

SSH client
Login into AWS EC2 Instance using Key Pair

Overview of AWS Free Tier and Pricing

As you might be familiar with creating an EC2 instance. Now it is time for you to understand some of the nuances related to the pricing and free tier.

You can go through the official AWS Documentation on AWS Free Tier which contains the eligibility for AWS Free Tier such as

Whenever someone signup for AWS Free Tier actually gives them 12 months after that there's nothing free in AWS unless and until you get credits from AWS, You can also easily get credits if you are a startup

For each and every service there will be free tier limits you can only use up to those limits.

Some of the services might not have free-tier benefits you will not be able to get those services for free

You should be careful while using services and keep pricing in mind as you gave your card details while creating your AWS account, Hence if you cross free tier limits you will be charged on your credit card, At times AWS might wave some of the charges but it is a one time only wave-off. So it is very important for you to understand the free tier limits based on the service you are using.

When it comes to EC2 instances there are States for every EC2 instance which basically is the status of the instance. When the instance is in the stopped state or terminated state you won't be charged for the usage of the instance, You will be charged depending on the instance for its running state based on per-hour pricing. You can change the instance's state by selecting your instance, clicking on the instance state, and clicking on your desired state.

If the instance is in the stopped state even the free tier hours won't be counted they will be counted if the instance is in the running state.

In a month you will be having max 744 free tier hours for which you can keep your free tier-type instances up and running, If it crosses the limit for that month you will be charged, And if you want to run ‘n’ number of instances the combined hours must not cross the free tier hours limit.

Instance Dashboard

To get an estimated cost for the service usage, you can search for the AWS pricing calculator on google.

AWS pricing calculator

Click on create an estimate to get the estimated cost for the service you need.

Search for the service you want to get the estimated cost, Here it is EC2

Configuration of Amazon EC2 cost

Select the location as the cost might sometimes vary depending on the region you are using the service.

Configuration of Amazon EC2 cost

Enter the operating system and minimum memory details depending on your requirements

Configuration of Amazon EC2 cost

You can search for types as well by selecting your required instance type, and you can also add the number of instances you want to run with the same configurations by selecting the number in Quantity.

Configuration of Amazon EC2 cost

Select the storage amount and type of storage, here it is general purpose and 30GB

Configuration of Amazon EC2 cost

after adding you can click on save and add view summary to get the estimated cost

Configuration of Amazon EC2 cost

You can also save and add service to redirect to your AWS account and simply run the instance with the same configurations you selected directly.

Added EC2 estimate

So as you can see the estimate is around 24.77 USD per month and 297.24 USD per year.

This is how you should come up with the estimate for the services that are being used as part of your pursuit of understanding AWS. It is very important to understand it is just an estimate the final costs might vary, The final cost will vary depending on the usage of your services and also depending upon other additional charges such as data transfer, etc.,

Make sure you understand the relevance of the free tier and also be comfortable with the pricing calculator to get an estimate also configure alerts and notifications as part of the billing so that you are notified if certain thresholds are met.

Overview of AWS Free Tier and Pricing

Overview of AWS Web Console Cloud Shell

Let's understand how to get the details about the instances that are being provisioned from AWS using an essential tool called CloudShell, To launch the cloud shell you just have to click on the CloudShell icon which is on the top right of the AWS console, It will take care of launching the cloud shell for you. It will use a docker container under the hood and you should be able to access all the services and their components in AWS using the cloud shell

CloudShell icon

CloudShell automatically provides you quite a lot of stuff such as pre-installed tools such as AWS-CLI, Python, NOde.js, and more, and 1GB of free storage per AWS region, and the files will be saved in your home directory and they will be available in future sessions for the same AWS region, within each AWS region there will be home directory associated with your cloud shell you should be able to access those files across the sessions within the same AWS region

CloudShell welcome popup

You can see it already has python, You can launch python CLI by using Python command

As part of python CLI, you should be able to use boto3 as well, boto3 is python based AWS SDK to interact with AWS services not only python but also libraries such as boto3 are actually pre-installed on this machine

type exit() to come out of python CLI, on top of python and boto3 it also has AWS CLI.

Validate AWS CLI by typing aws and by pressing enter then you'll be prompted to check the command and type a proper command.

Cloudshell interface

You can check for help in order of prompt as follows

aws help , aws <command> help , aws <command> <subcommand> help

Validate help for the EC2 command so that you can get the command to get the details related to the instance that you created

aws ec2 help
AWS EC2 help

the sub-command you need to get the details related to your EC2 instance is describe-instances so use the following command

aws ec2 describe-instances help
AWS EC2 describe-instances help command

Now to get the details related to your EC2 instance, Copy your instance id from your AWS console and use the instance ids tag and the id in the command as follows

aws ec2 describe-instances --instance-ids i-03e1baf878331a2e
AWS EC2 describe-instances command

Now you should be able to see the details about the instance id that you passed. This is how you can get started with CloudShell. CloudShell facilitates you to manage the services and components of the services in ad ok manner. In earlier days there used to be EC2 instances which used to be called Bastian servers, Now there is no need to have a Bastian server for regular ad hok tasks you should be able to leverage the cloud shell under your account and you should be able to maintain services and their components. Make sure you are comfortable with CloudShell, it will actually facilitate you to streamline the process of managing the services and components in AWS.

Overview of AWS Web Console Cloud Shell

Overview of AWS EC2 Instance Concepts

When it comes to AWS, It is nothing but a cloud platform there are multiple data centers in multiple regions related to the AWS cloud platform. In this case, N.Virginia is used as the region which means data center in that N.Virginia has servers and the EC2 instances are provisioned from that region

There will be n number of data centers in this region you can consider this as one data center and as part of this data center, there are a lot of physical servers in a given data center within N.Virginia.

Keep in mind that there might be more than one data center in a given region each data center might have so many physical servers, In this case, 4 physical servers are represented as ps1, ps2, ps3, ps4.

Physical servers on top of a data center in a region

A virtual machine is created which is represented as gsdemo which is shown below, This virtual machine is created using Ubuntu 20.04 operating system, When a virtual machine is provisioned a user is created for that virtual machine, the user name is ubuntu, there will be the home directory for user ubuntu in the file system of this virtual machine, It will have a hidden folder by name .ssh which will automatically be created.

When you created this EC2 instance the key-pair gsdemo is used which is already downloaded to the user's PC as shown below under the downloads folder gsdemo.pem is available and is automatically downloaded when you have actually created the key-pair as the EC2 instance is created using gsdemo key-pair, the public key associated with that key-pair will be copied to something called as authorized keys under .ssh folder. So there will be a file by the name authorized_keys under .ssh that will contain the public key associated with gsdemo key-pair

EC2 instance connection architecture

log in to your EC2 instance and use the following command to get into the .ssh folder

cd .ssh

use ls -ltr to list the files in that directory

authorized keys location

As this EC2 instance is created using gsdemo key-pair, the public key of the gsdemo will be copied into this authorized_keys, as the authorized_keys contain the public key of the gsdmeo. Using the gsdemo private key which is nothing but the .pem file, you can connect to this EC2 instance without any issues.

This is what happens when provisioning an EC2 instance from AWS, there will be a virtual machine on top of physical servers in one of the data centers in the AWS region, and that virtual machine will also have the Operating system along with the file system. As part of the file system, there will be a hidden folder by the name .ssh. It will contain authorized_keys, and the public key associated with the key-pair will be part of authorized_keys under .ssh in the virtual machine, the private key is already downloaded onto your PC using the combination of the private key and public key in authorized keys, you will be able to authenticate to the Virtual machine, The capacity of the Virtual Machine is defined by the instance type and the storage that is used while creating the virtual machine, the instance type that is used to create this virtual machine is t2.micro.

EC2 instance connection architecture
Overview of AWS EC2 Instance Concepts

Managing AWS EC2 Instances

As part of creating an EC2 instance, it is important to know how to manage EC2 instances. You can check your instance status in the EC2 Instance dashboard

EC2 Instance Dashboard

You can select the desired state for your instance by clicking on the instance state and choosing your required state. When in a stopped state you won't be charged for the instance, You will be charged only for the time it is up and running. You can terminate the instance if it is for learning purposes after the use of the instance is done.

instance state

Click on the Instance state and stop the instance after use or terminate it if it is not necessary.

The instance is in a stopped state
Managing AWS EC2 Instances

🙏🏼Thank you, for reading the article. If you find it valuable please follow our publication DevOps Engineering on Cloud

🚨👉🏼 You can also check the complete udemy course (Linux Shell Commands for Absolute Beginners using Ubuntu 20x)🔗Referral link

Thanks to Vamsi Penmetsa

--

--