In this tutorial, you will learn step by step guide to create EC2 instance on AWS.
What is Amazon EC2 Instance?
An EC2 instance is nothing but a virtual machine in Amazon terminology. It stands for Elastic Compute Cloud.
In simple words, its like your machine – where you will install your applications and perform tasks. You can access EC2 instance from anywhere in the world and manage on the go.
Read the official Amazon AWS documentation for more information.
Table of contents
Create EC2 Instance on AWS
Follow bellow steps to create EC2 instance on AWS.
Login and access to AWS Services
- Login to your AWS Console, click on Services tab at the top and select the EC2 under Compute.
- Next you will be directed to EC2 Dashboard, where you will find no of instances running, key pairs, Elastic IPs, security groups, etc.,
Step 2: On the top right, select AWS Region in which you want to provision the EC2 server.
As of now AWS provides 21 Regions all over the globe and this number may increase in future. Here, we have selected region N. Virginia.
Step 3: Switch back to EC2 Dashboard and click on Launch instance.
You will see two options:
- Launch instance – launch instance from start.
- Launch instance from template – choose a pre-filled template to launch instance.
Select Launch instance and as soon as you click on Launch instance, you will be redirected to instance creation wizard.
Configure your instance as follows,
- You will be asked to choose your AMI (Amazon Machine Image). Its basically an operating system that you will be using to create your instance. For example, installing an operating system (windows or linux) on your machine.
- Once you selected the your desired operating system, an instance will automatically booted with the OS that you opted.
For this example, select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type and click on Select.
Choose Instance Type
Select the instance type based on your business requirements,
- Let’s choose the t2.micro (free trier) – which has 1 vCPUs, 2.5 GHz, and 1 GiB memory.
- Next click on configure instance details.
Configure the instance as follows or depends on your business needs.
Step 1: Choose the no of instances you want to create with the same configuration. You can create up to 20 instances.
Step 2: Under purchasing options, keep the Request Spot instances unchecked. This is required when we wish to launch spot instances instead of on-demand instances.
Step 3: Now we will need to configure basic networking details for EC2 instances.
- In the Network configuration,
- You can create new VPC
- You can select the existing VPC
For now let’s use the default VPC and will learn how to create new VPC in next tutorial.
- In the Subnet configuration,
- You can create new subnet
- You can select the existing subnet
Once your instance is launched in a public subnet, AWS will assign a dynamic public IP to it from their pool of IPs.
Step 3: You can either choose Auto-assign IP – If you want to AWS to assign it an IP automatically, or you want to do it manually later.
Step 4: Next keep Placement group unchecked and Capacity reservation open. You can change these values as per your needs.
Placement group is useful when you want greater redundancy and higher network throughput.
Capacity reservation useful when if you want to reserve capacity for your EC2 instances in specific Availability Zones.
Step 5: Configure the Domain join directory and the IAM role.
Domain join enables you to join your instance to a directory you’ve defined in AWS Directory Service, giving you a single sign-on and centralized management experience across a network of Windows and Linux instances.
We have not joined due to some access related issues but in your organization you can select the directory or you can create directory (in case, if you have an access).
Step 6: Now configure the remaining options as follows,
- Select the instance behavior when OS level shutdown is performed. You can either select Stop or Terminate.
- Enable this If you want to save contents of the instance’s RAM to root volume.
- Enable If you want to protect instance from being accidentally terminated. Note: If you enable then you can’t terminate instance from API or AWS Console until you disable.
- Enable this If you want to monitor, collect instance metrics thru Amazon CloudWatch.
- You will get three options to choose,
- Dedicated Host
- Elastic Inference provides cost efficient hardware acceleration for deep learning inference for all EC2 instance types, at a fraction of the cost of standalone GPU instances.
- Selecting Unlimited for the credit specification allows applications to burst beyond the baseline for as long as needed at any time.
- Specify Amazon EFS file systems to mount to your instance.
If you are using free trier then please do check above features charges and select if its necessary.
Step 7: Configure advanced details (1) if required and click on Add Storage (2).
Here you will see the instance has been automatically provisioned a General Purpose SSD root volume of 8GiB.
- You can either choose the default 8 GiB General Purpose SSD volume or you can increase If required.
- AWS provides 3 types of EBS volumes- Magnetic, General Purpose SSD (gp2,gp3), Provisioned IOPs( io1,io2). You can select any one depends your your application’s IOPs needs.
- Click on Add Tags
This gives visibility to the AWS account administrator when there are multiple instances and the instances should be tagged based on the department/environment such as DEV/SIT/PROD, etc.,
- Add your tags in key-value pair
- Click on Configure Security Group
Configure Security Group
In this next step we can configure security groups to restrict traffic to our instance ports. This is an added firewall mechanism provided by AWS apart from your instance’s OS firewall.
This configuration is up to your business needs and how you are going to access your instances.
Note: You can either create new security group or choose an existing security group.
- Select the types (SSH, HTTP, HTTPS, etc.,)
- Choose the Source (Custom, Anywhere or Your own IP)
- Once you configured then click on Review and Launch
Configure Security Group
Step 1: Review your instance configuration and edit if required and click on Launch.
Step 2: In the next screen, you can either select the existing key pair or create new key pair.
- Select Create a new key pair
- Name your key pair
- Download the Key Pair
- Finally click on Launch Instances
Make sure to store these key pair in secure place to avoid unauthorized access.
That’s simple! Your instances will be up and running in less than 5 minutes and Click on Instances tab see the status of your instances.
Now click on any one of your instances.
There you can see that the instance has received a Public IP from the pool of AWS automatically.
But If you want to persist an IP even if my instance is stopped and restarted then you can use Elastic IP address.
Follow below steps to create EIP and associate EIP to your instance.
Create EIP and Associate to Instance
An EIP is a static public IP provided by AWS and its stands for Elastic IP. Basically when you create an instance, it will receive a public IP from the AWS’s pool automatically.
If you stop/reboot your instance, this public IP will change. In order have a static IP for your instance, you can use an EIP.
Step 1: On the left side (EC Dashboard) panel, click on Elastic IPs under Network & Security.
Step 2: Next click on Allocate Elastic IP Address
In the next screen, select the Network Border Group, Tags (optional) and click on Allocate.
Step 3: Now in the Elastic IPs dashboard, select any Elastic IP that we created before, click on Actions and select Associate Elastic IP address.
Step 4: In the next screen,
- Select Resource Type as Instance
- Select the Instance from drop down list
- Select the private IP address from the drop down list
- Click on Allocate
Step 5: Now switch back to Instances and verify public IP address.
There you can see you got a new Public IP address which is reserved for your instance even if your instance restart/crash.
We hope this tutorial helped you to understand what is EC2, how to create EC2 instance and also how to create and associate Elastic IP address to an instance.
If you feel that we missed some vital information, please do let us know in the comment section and we are happy to take your suggestions.