How To Create EC2 Instance in AWS - Step by Step Tutorial
How To Create EC2 Instance in AWS - Step by Step Tutorial
The instance will be charged per hour with different rates based on the type of the instance
chosen. AWS provides multiple instance types for the respective business needs of the user.
Thus, you can rent an instance based on your own CPU and memory requirements and use it
as long as you want. You can terminate the instance when it’s no more used and save on
costs. This is the most striking advantage of an on-demand instance- you can drastically save
on your CAPEX.
Let us see in detail how to launch an on-demand EC2 instance in AWS Cloud.
Login to your AWS account and go to the AWS Services tab at the top left corner.
Here, you will see all of the AWS Services categorized as per their area viz. Compute,
Storage, Database, etc. For creating an EC2 instance, we have to choose Computeà EC2 as
in the next step.
(/images/3-2016/032816_0629_CreatinganA1.png)
Open all the services and click on EC2 under Compute services. This will launch the
dashboard of EC2.
Here is the EC2 dashboard. Here you will get all the information in gist about the AWS EC2
resources running.
/
(/images/3-2016/032816_0629_CreatinganA2.png)
Step 2) On the top right corner of the EC2 dashboard, choose the AWS Region in which you
want to provision the EC2 server.
Here we are selecting N. Virginia. AWS provides 10 Regions all over the globe.
(/images/3-
2016/032816_0629_CreatinganA3.png)
/
Step 3) In this step
Once your desired Region is selected, come back to the EC2 Dashboard.
Click on 'Launch Instance' button in the section of Create Instance (as shown below).
(/images/3-
2016/032816_0629_CreatinganA4.png)
Instance creation wizard page will open as soon as you click 'Launch Instance'.
Choose AMI
Step 1) In this step we will do,
1. You will be asked to choose an AMI of your choice. (An AMI is an Amazon Machine Image.
It is a template basically of an Operating System platform which you can use as a base to
create your instance). Once you launch an EC2 instance from your preferred AMI, the
instance will automatically be booted with the desired OS. (We will see more about AMIs
in the coming part of the tutorial).
2. Here we are choosing the default Amazon Linux (/unix-linux-tutorial.html)(64 bit) AMI.
/
(/images/3-2016/032816_0629_CreatinganA5.png)
1. We will choose t2.micro instance type, which is a 1vCPU and 1GB memory server offered
by AWS.
2. Click on "Configure Instance Details" for further configurations
(/images/3-2016/032816_0629_CreatinganA6.png)
In the next step of the wizard, enter details like no. of instances you want to launch at a
time.
Here we are launching one instance.
/
Configure Instance
Step 1) No. of instances- you can provision up to 20 instances at a time. Here we are
launching one instance.
(/images/3-2016/032816_0629_CreatinganA7.png)
Step 2) Under Purchasing Options, keep the option of 'Request Spot Instances' unchecked as
of now. (This is done when we wish to launch Spot instances instead of on-demand ones. We
will come back to Spot instances in the later part of the tutorial).
(/images/3-2016/032816_0629_CreatinganA8.png)
Step 3) Next, we have to configure some basic networking details for our EC2 server.
/
You have to decide here, in which VPC (Virtual Private Cloud) you want to launch your
instance and under which subnets inside your VPC. It is better to determine and plan this
prior to launching the instance. Your AWS architecture set-up should include IP ranges for
your subnets etc. pre-planned for better management. (We will see how to create a new
VPC in Networking section of the tutorial.
Subnetting should also be pre-planned. E.g.: If it's a web server you should place it in the
public subnet and if it's a DB server, you should place it in a private subnet all inside your
VPC.
Below,
Here I have selected an already existing VPC where I want to launch my instance.
(/images/3-2016/032816_0629_CreatinganA9.png)
A VPC consists of subnets, which are IP ranges that are separated for restricting access.
Below,
1. Under Subnets, you can choose the subnet where you want to place your instance.
2. I have chosen an already existing public subnet.
/
3. You can also create a new subnet in this step.
(/images/3-2016/032816_0629_CreatinganA10.png)
Once your instance is launched in a public subnet, AWS will assign a dynamic public IP to
it from their pool of IPs.
You can choose if you want AWS to assign it an IP automatically, or you want to do it
manually later. You can enable/ disable 'Auto assign Public IP' feature here likewise.
Here we are going to assign this instance a static IP called as EIP (Elastic IP) later. So we
keep this feature disabled as of now.
/
(/images/3-2016/032816_0629_CreatinganA11.png)
In the following step, keep the option of IAM role 'None' as of now. We will visit the topic
of IAM role in detail in IAM services.
(/images/3-2016/032816_0629_CreatinganA12.png)
Shutdown Behavior – when you accidently shut down your instance, you surely don't
want it to be deleted but stopped.
/
Here we are defining my shutdown behavior as Stop.
(/images/3-2016/032816_0629_CreatinganA13.png)
In case, you have accidently terminated your instance, AWS has a layer of security
mechanism. It will not delete your instance if you have enabled accidental termination
protection.
Here we are checking the option for further protecting our instance from accidental
termination.
(/images/3-2016/032816_0629_CreatinganA14.png)
/
Step 9) In this step,
Under Monitoring- you can enable Detailed Monitoring if your instance is a business
critical instance. Here we have kept the option unchecked. AWS will always provide Basic
monitoring on your instance free of cost. We will visit the topic of monitoring in AWS
Cloud Watch part of the tutorial.
Under Tenancy- select the option if shared tenancy. If your application is a highly secure
application, then you should go for dedicated capacity. AWS provides both options.
(/images/3-2016/032816_0629_CreatinganA15.png)
Click on 'Add Storage' to add data volumes to your instance in next step.
/
(/images/3-2016/032816_0629_CreatinganA16.png)
Add Storage
Step 1) In this step we do following things,
In the Add Storage step, you'll see that the instance has been automatically provisioned a
General Purpose SSD root volume of 8GB. ( Maximum volume size we can give to a
General Purpose volume is 16GB)
You can change your volume size, add new volumes, change the volume type, etc.
AWS provides 3 types of EBS volumes- Magnetic, General Purpose SSD, Provisioned IOPs.
You can choose a volume type based on your application's IOPs needs.
(/images/3-2016/032816_0629_CreatinganA17.png)
/
Tag Instance
Step 1) In this step
you can tag your instance with a key-value pair. This gives visibility to the AWS account
administrator when there are lot number of instances.
The instances should be tagged based on their department, environment like
Dev/SIT/Prod. Etc. this gives a clear view of the costing on the instances under one
common tag.
(/images/3-2016/032816_0629_CreatinganA18.png)
(/images/3-2016/032816_0629_CreatinganA19.png)
Review Instances
Step 1) In this step, we will review all our choices and parameters and go ahead to launch our
instance.
/
(/images/3-2016/032816_0629_CreatinganA20.png)
Step 2) In the next step you will be asked to create a key pair to login to you an instance. A
key pair is a set of public-private keys.
AWS stores the private key in the instance, and you are asked to download the private key.
Make sure you download the key and keep it safe and secured; if it is lost you cannot
download it again.
/
(/images/3-2016/032816_0629_CreatinganA21.png)
When you download your key, you can open and have a look at your RSA private key.
(/images/3-2016/032816_0629_CreatinganA22.png)
/
Step 3) Once you are done downloading and saving your key, launch your instance.
(/images/3-2016/032816_0629_CreatinganA23.png)
/
(/images/3-
2016/032816_0629_CreatinganA24.png)
(/images/3-2016/032816_0629_CreatinganA25.png)
/
Click on the 'Instances' option on the left pane where you can see the status of the
instance as 'Pending' for a brief while.
(/images/3-2016/032816_0629_CreatinganA26.png)
Once your instance is up and running, you can see its status as 'Running' now.
Note that the instance has received a Private IP from the pool of AWS.
/
(/images/3-2016/032816_0629_CreatinganA27.png)
Step 1) On the left pane of EC2 Dashboard, you can go to 'Elastic IPs' as shown below.
/
(/images/3-2016/032816_0629_CreatinganA28.png)
/
(/images/3-2016/032816_0629_CreatinganA29.png)
(/images/3-2016/032816_0629_CreatinganA30.png)
Your request will succeed if you don't have 5 or more than 5 EIPs already in your account.
/
(/images/3-
2016/032816_0629_CreatinganA31.png)
(/images/3-2016/032816_0629_CreatinganA32.png)
(/images/3-2016/032816_0629_CreatinganA33.png)
Step 6) Come back to your instances screen, you'll see that your instance has received your
EIP.
(/images/3-2016/032816_0629_CreatinganA34.png)
Step 7) Now open putty from your programs list and add your same EIP in there as below.
/
(/images/3-
2016/032816_0629_CreatinganA35.png)
1. Go to Auth
2. Add your private key in .ppk (putty private key) format. You will need to convert pem file
from AWS to ppk using puttygen
/
(/images/3-
2016/032816_0629_CreatinganA36.png)
Once you connect, you will successfully see the Linux (/unix-linux-tutorial.html)prompt.
Please note that the machine you are connecting from should be enabled on the instance
Security Group for SSH (like in the steps above).
(/images/3-
2016/032816_0629_CreatinganA37.png)
Once you become familiar with the above steps for launching the instance, it becomes a
matter of 2 minutes to launch the same!
You can now use your on-demand EC2 server for your applications.
Your Spot instance runs whenever your bid exceeds the current market price. The price of a
spot instance varies based on the instance type and the Availability Zone in which the
instance can be provisioned.
When your bid price exceeds the market spot price of the instance called as the ‘spot price,'
your instance stays running. When the spot price overshoots the bid price, AWS will
terminate your instance automatically. Therefore, it is necessary to plan the spot instances in
your application architecture carefully.
1. On the EC2 Dashboard select 'Spot Requests' from the left pane under Instances.
2. Click on the button 'Request Spot Instances" as shown below.
(/images/3-2016/032816_0656_CreatingaSp4.png)
Spot instance launch wizard will open up. You can now go ahead with selecting the
parameters and the instance configuration.
(/images/3-
2016/032816_0656_CreatingaSp5.png)
Step 1) Select an AMI- an AMI is a template consisting of the OS platform and software to be
installed in the instance. Select your desired AMI from the existing list. We are selecting
Amazon Linux AMI for this tutorial.
(/images/3-2016/032816_0656_CreatingaSp6.png)
Step 2) Capacity Unit- a Capacity Unit is your application requirement. You may decide to
launch an instance based on the instance type, vCPU or custom configuration like your
choice of vCPU/memory/storage requirements. Here we are selecting an Instance.
/
(/images/3-2016/032816_0656_CreatingaSp7.png)
If you wish to customize the capacity, you can add your choice of
1. vCPU,
2. Memory and
3. Instance storage as below.
(/images/3-2016/032816_0656_CreatingaSp8.png)
Step 3) Target Capacity depicts how many spot instances you wish to maintain in your
request. Here we are selecting one.
/
(/images/3-2016/032816_0656_CreatingaSp9.png)
Step 4) Bid Price – this is the maximum price we are ready to pay for the instance. We are
going to set a particular price per instance/hour. This is the simplest to calculate based on
our business requirement. We will see ahead how we should determine the bid price so that
our bid price always remains high and doesn't exceed the spot price so that our instance
keeps running.
/
(/images/3-2016/032816_0656_CreatingaSp10.png)
just below the bid price you can see a button of Pricing History. Click on that as shown
below.
(/images/3-2016/032816_0656_CreatingaSp11.png)
Here in Pricing History, we can see a graph depicting instance pricing trends with historical
data. You can select the parameters and get an idea of the pricing of our desired instance
over a period of time.
/
1. Select the product. We have selected our Linux AMI.
2. Select the instance type. We have selected m3.medium.
3. Note the average prices for over a day here.
Thus, from the chart below, we can see that the instance type that we are planning to
provision lies in the pricing range of $0.01xx, and it seems that Availability Zone 'us-east 1a'
has the lowest price.
(/images/3-2016/032816_0656_CreatingaSp12.png)
cont. to step 4.
For the sake of maintaining our instance always available and if it falls within our budget, we
can quote a higher bid price. Here we have quoted a slightly higher price of $0.05.
/
(/images/3-2016/032816_0656_CreatingaSp13.png)
(/images/3-2016/032816_0656_CreatingaSp14.png)
/
Step 5) Once we are done looking at the trends and quoting our bid price, click on next.
(/images/3-2016/032816_0656_CreatingaSp15.png)
Step 1) Allocation Strategy – it determines how your spot request is fulfilled from the AWS's
spot pools. There are two types of strategies:
Diversified – here, spot instances are balanced across all the spot pools
Lowest price – here, spot instances are launched from the pool which has lowest price
offers
For this tutorial, we'll select Lowest Price as our allocation strategy.
/
(/images/3-2016/032816_0656_CreatingaSp16.png)
Step 2) Select the VPC- we'll select from the list of available VPCs that we have created
earlier. We can also create a new VPC in this step.
(/images/3-2016/032816_0656_CreatingaSp17.png)
Step 3) Next we'll select the security group for the instance. We can select an already existing
SG or create a new one.
/
(/images/3-2016/032816_0656_CreatingaSp18.png)
Step 4) Availability Zone- we'll select the AZ where we want to place our instance based on
our application architecture. We are selecting AZ- us-east-1a.
(/images/3-
2016/032816_0656_CreatingaSp19.png)
Step 5) Subnets- we are going to select the subnet from our list of already available list.
/
(/images/3-2016/032816_0656_CreatingaSp20.png)
Step 6) Public IP- we'll choose to assign the instance a public IP as soon as it launches. In this
step, you can choose if you want AWS to assign it an IP automatically, or you want to do it
manually later. You can enable/ disable 'Auto assign Public IP' feature here likewise.
(/images/3-2016/032816_0656_CreatingaSp21.png)
AWS stores the private key in the instance, and you are asked to download the private key.
Make sure you download the key and keep it safe and secured; if it is lost you cannot
download it again.
/
After selecting public IP, here we are selecting a key which we already have created in our
last tutorial.
(/images/3-2016/032816_0656_CreatingaSp22.png)
(/images/3-2016/032816_0656_CreatingaSp23.png)
1. We can also download a JSON file with all the configurations. Below is our JSON file.
/
(/images/3-2016/032816_0656_CreatingaSp24.png)
After we are done reviewing, we can proceed with the launching by clicking the Launch
button as shown below.
(/images/3-2016/032816_0656_CreatingaSp25.png)
Once we select Launch, we can see a notification about the request getting created.
/
(/images/3-2016/032816_0656_CreatingaSp26.png)
The spot request creation wizard will close, and the page will automatically direct back to
the EC2 Dashboard.
You can see as shown below that the State of our request is 'open' which means that it is
getting evaluated from the AWS's side. AWS EC2 will check if the required instance is
available in its spot pool.
(/images/3-2016/032816_0656_CreatingaSp27.png)
After a couple of minutes, you can see that the state is changed to 'active', and now our spot
request is successfully fulfilled. You can note the configuration parameters below.
/
(/images/3-2016/032816_0656_CreatingaSp28.png)
Summary:
Thus, we saw in detail how to create an on-demand EC2 instance in this tutorial. Because it is
an on-demand server, you can keep it running when in use and 'Stop' it when it's unused to
save on your costs.
You can provision a Linux or Windows EC2 instance or from any of the available AMIs in AWS
Marketplace based on your choice of OS platform.
If your application is in production and you have to use it for years to come, you should
consider provisioning a reserved instance to drastically save on your CAPEX.
Here, we saw how to create a Spot Instance request successfully by determining our bid
price.
Spot instances are a great way to save on costs for instances which are not application
critical. A common example would be to create a fleet of spot instances for a task such as
image processing or video encoding. In such cases, you can keep a cluster of instances under
a load balancer.
If the bid price exceeds the spot price and your instance is terminated from AWS's side, you
can have other instances doing the processing job for you. You can leverage Auto scaling for
this scenario. Avoid using Spot instances for business critical applications like databases etc.
/
Next (/modifying-amazon-ec2-instance-parameters.html)
/
AWS Tutorial
8) Digitalocean Vs AWS (/digitalocean-vs-aws.html)
(https://www.facebook.com/guru99com/)
(https://twitter.com/guru99com)
(https://www.linkedin.com/company/guru99/)
(https://www.youtube.com/channel/UC19i1XD6k88KqHlET8atqFQ)
(https://forms.aweber.com/form/46/724807646.htm)
About
About Us (/about-us.html)
Advertise with Us (/advertise-us.html)
Write For Us (/become-an-instructor.html)
Contact Us (/contact-us.html)
Career Suggestion
SAP Career Suggestion Tool (/best-sap-module.html)
Software Testing as a Career (/software-testing-career-
complete-guide.html)
Interesting
Books to Read! (/books.html)
Blog (/blog/)
Quiz (/tests.html)
eBook (/ebook-pdf.html)
Execute online
/
Execute Java Online (/try-java-editor.html)
Execute Javascript (/execute-javascript-online.html)
Execute HTML (/execute-html-online.html)
Execute Python (/execute-python-online.html)
/
/