Beginners Guide to AWS EC2

In this AWS tutorial, we are going to have an insight into AWS EC2 service and how we can span EC2 instances in the AWS management console and play around with our created EC2 instances.

For the last few years, the cloud is a buzz in the market and among various cloud service providers, AWS is still the most popular and the leading cloud provider in the market. If you are new to cloud development, you may start with the cloud introduction.

1. What is EC2?

EC2 (Elastic Compute Cloud) is a service provided by AWS to deploy our applications on the cloud. When we are creating an application then what is the first thing that comes to our mind? Where are we going to deploy our application, right?

For a typical on-premise set-up (where the servers and the entire infrastructure have been maintained by the company itself), the application is deployed on physical servers located in corporate data centers.

So where and how will we deploy our application in the cloud? The answer is by renting virtual servers which are nothing but EC2 instances.

2. Important Features of EC2 Service

The main features of an EC2 service are:

  • Create and manage the lifecycle of EC2 instances.
  • Load Balancing and Auto-scaling for multiple EC2 instances.
  • Attach storage (& network storage) to EC2 instances.
  • Manage network connectivity for EC2 instances.

Read More:

3. Setting Up an EC2 Instance

Let’s now play around EC2 instances in AWS Management Console. We will create an instance, configure it and then launch it.

3.1. Creating EC2 Instance

Login into AWS Management Console via Root or IAM user.

Search for EC2 in the services search box and click on EC2

Click on Instances and click on Launch Instances there to launch a new EC2 instance

3.2. Selecting Tags

Tags are just the labels that we can assign to an AWS resource. Each tag consists of a key and an optional value. Tags help us in categorizing the resources based on our user-defined custom criteria so we can easily identify them from a list of similar resources.

For example, we can provide a tag key as ‘Name’ and value as ‘First EC2 Instance’ or can provide a tag key as ‘Environment’ and value as ‘Dev’.

Adding Tags to an EC2 Instance

3.3. Selecting AMI

Then select an AMI for our EC2 instance. AMI is Amazon Machine Image which contains the software configuration(operating system, application server and applications) required to launch our EC2 instance.

AMI is a pre-defined image with all the necessary OS and software configurations that we can directly use to spun-up an EC2 instance. There are a lot of AMIs available here, but if we are on the free tier of AWS then select the ‘Amazon Linux’ image type.

AMI selection for an EC2 Instance

3.4. Selecting Instance Type

Then we have to select an appropriate instance type for our instance. An instance type is an optimized combination of compute (CPU, GPU), memory, disk(storage) and network capabilities for specific workloads.

AWS provides 40+ instance types for different workloads but if we are on free tier limit then select instance type as ‘t2.micro

Instance Type for an EC2 Instance

3.5. Creating Key Pair

After instance type, we need to provide a key pair that is a combination of public and private keys which is required to login into our EC2 instance.

AWS uses public key cryptography to login into our EC2 instances instead of using a login id and password. Generate a new keypair thereby providing the keypair name and other default configuration.

Key Pair creation for an EC2 Instance

3.6. Configuring Security Group

Next, we have to select a security group for our EC2 instance. Security Groups are the virtual firewalls in front of our EC2 instance that allows/blocks incoming and outgoing traffic to and from an EC2 instance.

Create a new Security Group and allow SSH traffic to an EC2 instance from anywhere.

Security Group creation for an EC2 Instance

3.7. Launching the Instance

Leave the default storage configuration as it is and then click on Launch Instance.

Remaining Default Configuration

we can see a new EC2 instance is live now.

Click on the instance-id that is created that will take we to the EC2 instances page where we can see our created instance in Running status.

We can select created EC2 instance and see the details of it like instance-id, AMI-id, public-IP address, private-IP address, security group, storage configuration, monitoring and tags.

4. Start and Stop an EC2 Instance

By clicking on the ‘Instance state‘ button we can:

  • stop a running EC2 instance
  • start a stopped EC2 instance
  • reboot/restart an instance
  • terminate an existing EC2 instance

5. Connecting to an EC2 Instance

We can connect to our EC2 instance by clicking on the Connect button.

For example, we are connecting to EC2 instance connect with default user as ec2-user. Click on Connect button.

We can see the EC2 console opens up and we are now connected to our EC2 instance via SSH.

This is all about AWS EC2 instances and EC2 service and how to launch a new EC2 instance from AWS management console and perform some of the actions with our newly launched EC2 instances.

6. Conclusion

In this AWS EC2 tutorial, we learned to create and configure an EC2 instance from scratch and finally launched it. We also learned to start and stop the instance using the various menu options.

Finally, we were able to connect to EC2 instance and opened up the console for further working on it.

Happy Learning!!


Notify of

Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.