Getting started with EC2 instance
Amazon EC2(Elastic Compute Cloud) provides secure, resizable compute capacity in the cloud, eliminating the need to invest in hardware.
- Provides on-demand, scalable compute capacity in the AWS Cloud
- Compute Instances are known as EC2 instances
- Allows various configurations of CPU, memory, storage and networking capabilities
- Instances can be launched in multiple regions
- Also referred to as IaaS (Infrastructure as a Service)
- Can use the EC2 Instance as an application server, a database server, or maybe as a batch-processing server
Creating an account in AWS and service recommendations
To create a new account first navigate to aws.amazon.com/free and then click Create a Free Account. AWS provides three types of free services.
1. Always free services
2. Services that are free for the first 12 months
3. Services that are available as short term trials
How to create an EC2 instance?
After creating the account in AWS services, log in to AWS console and click on the EC2 below the compute as shown in the below screenshot.
Click on the launch instance as shown in the below picture
Step 3-Choose AMI (Amazon Machine Image)
The Amazon machine image identifies the operating system that will be installed on the EC2 instance. An AMI is a template or a configuration that contains the information needed to install the OS on an EC2 Instance. Every AMI has an AMI ID associated with it. Some of the AMIs only contain the operating system while the others contain the OS along with a preinstalled application. The AWS marketplace is another place where you can go and find third party AMIs. Selecting an AMI is the first step in launching an EC2 instance and it identifies the operating system and the applications that will be installed on top of the EC2 instance.
AMI is a template of operating systems, servers, and other Softwares like the ubuntu server, the windows server, and many more which can be chosen based on the requirements of the users. There are premium and free tier available based on the application user can choose.
Step 4-Choose Instance Type
By default, it selects the T2 micro size, which provides one virtual CPU, and one GB of RAM. An instance type is a combination of CPU, memory, storage, and networking capacity.
There are five families:
1. General purpose-General purpose EC2 instances provide a balance of computing, memory, and networking resources. This is ideal for use cases such as web servers. Under the general-purpose family, you have different types of EC2 instances. For example, you have A1, T3, T2, M5, and M4.
2. Compute optimized-Compute optimized instances provide more CPU capacity or more computing power. It is ideal for use cases such as batch processing, log processing, gaming servers, and other workloads that require a lot of compute capacity. For example, C5, C5n, and C
3. Memory optimized-These instances are ideal for workloads that need a lot of memory.
4. Accelerated computing- These are instances that provide additional processing power by using hardware accelerators. This is ideal for use cases such as heavy graphic processing, performing complex calculations.
5. Storage optimized-These are designed for workloads that require a lot of reads and write operations to be performed, typically your databases. The use cases for these are NoSQL databases like Cassandra and MongoDB, in-memory databases and data warehousing.
More on Instance families and their use cases go to the documentation Link
There is a wide range of instances offered by the AWS services. The selection of instance types optimized to fit different use cases. These types have varying combinations of CPU, memory, storage, and networking capacity and give you the flexibility to choose the appropriate mix of resources for your applications.
Consider learning with the free tier, let us choose the free tier
Step 5-Configure Instance
There are a variety of configurations that you can select. You need to specify the Virtual Private Cloud and the subnet to which an EC2 Instance will belong.
VPC — logically isolated network range of your AWS account
Subnet — a range of IP addresses within your VPC
Go to AWS Console>search VPC>Your VPC
By default, you will have a VPC. So, every region in your AWS account will have a default VPC. The range for this one is 172.31.00/16. So, just to reiterate, a VPC is simply an IP range.
Along with this, we have some other configurations, click over the exclamatory mark to know more what each is related to. For the beginner, you can go ahead with default settings.
Step 6-Add storage
You need to add storage for the EC2 instance. Think about the desktop or laptop that you are using. It has a hard disk on which the operating system is installed. In a similar fashion, the EC2 instance needs to have a storage volume to install the operating system. These storage volumes are known as EBS (Elastic Block Store). EBS volumes are block-level storage volumes for use with EC2 instances. These are raw, unformatted storage volumes, meaning, by default, they do not have a file system installed on them. An EC2 instance can have multiple volumes, but only one volume can be attached to one instance. The EBS volume and the instance must be in the same availability zone. EBS volumes can persist independently from the life of an EC2 instance. This means, even if your EC2 instance has been terminated, you can still retain access to the EBS volume. By default, it has a root volume, on which the operating system will be installed. It has a specific type and you can change the type, and you can also add additional volumes.
To being, we shall go with default settings.
Step 7-Add a Tag
Tags are labels that you can attach to your EC2 instance, for identification purposes. Next step consists of tags which consist of key-value pair. No need to worry about it now move to the next step.
Step 8-Configure Security Group
A security group is a set of firewall rules that controls the traffic for your EC2 instance. The security group is like a wrapper around the EC2 instance. It controls any traffic that originates from and is destined to the EC2 instance. Let’s say you also have another EC2 instance in the same availability zone. This security group does not apply to the other EC2 instance. It could if you configure it that way, but by default, the same security group does not apply to the other instance. Security groups work at the instance level. By default, it creates a new security group, or you can just select an existing security group if you have one configured from earlier.
- There are separate rules that control inbound and outbound traffic
- Only allow rules can be specified, no deny rules
- By default, all outbound traffic is allowed, and all inbound traffic is blocked
- Security groups are stateful which means if you send a request from your instance, the response traffic for the request is allowed to flow in regardless of inbound security group rules
Now, we need to configure the security group for SSH with port 22, so that we can remote access to the machine we created on AWS services from the local system.
Review the selection made in the previous steps and make changes if any change is needed, warnings can be ignored and go-ahead and launch the instance.
Step 10-Key Pair
A Key Pair is used to log into an EC2 instance. Public-key cryptography uses two keys that are mathematically related to encrypt and decrypt data. One key is called the public key, while the other one is called the private key. Together, they are called a key pair.
To understand this, let’s say we have a piece of data that needs to be encrypted, to encrypt this we need a public key, when you apply the public key on the data, you get encrypted text. Now to get the original text back you will need a different key which is your private key. Apply the private key on the encrypted text and you will get your original text back.
It is important to note that private keys are regional, meaning if you create a key pair in one region you cannot use the same key pair to access the instances that belong to other regions.
Create a key pair or you can also launch without key pair, this will be used to login to an instance using ssh. You have to download the .pem file, remember it can not be accessed later so make sure you download it.
Now if you see this you are all set with creating an EC2 instance
Step 12- Stopping an Instance
Lastly, you need to stop the instance when your work is done because if you are not using free tier you will be charged for every minute the instance is up.
So to stop
In the next article, we will discuss how to connect into the instance created and a few basic commands on the instance.
Data Analytics| Data Engineering| Business Intelligence |Linkedin