How to Provision an AWS on-demand EC2 instance.

In this article, I’m going to teach you how to provision an EC2 instance in AWS.

To create instances, go to the EC2 section from the AWS Services main menu. Then select Instances from the left menu and then you will have a landing page as below.

Then click on the Launch Instance button, from there select Amazon Linux standard image (Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type. You can select any Amazon Machine Image you like based on your requirements.

Then in the next screen select a t2.micro instance, and then Click Configure Instance Details bottom button which is located on the bottom of the right-hand side. Please note that t2.micro is the only instance type that is free for the free tire. For other instances, you might have to pay an extra cost.n You can see the costs for each on-demand instances types here: https://aws.amazon.com/ec2/pricing/on-demand/

From next Configure Instance page select your custom VPC as Network and the public subnet as the Subnet if you want to create your EC2 in a custom VPC else leave everything as default and click Add storage from the bottom button.

From this Add Storage you can add new volumes if you want, but in most cases, the default volume is more than enough. If you want you can add New Volume or increase the default volume size. Then click Add tags button.

In the next page Add tags to identify the instance if you want. I’m adding a tag called Name with value WebServer and then Click Configure Security group button from the bottom buttons. Here we need to Create a new Security Group as follow. To do that select Create a new Security Group option and give Web-DMZ as for the security group name and the description. You can have any name you want, in my case that is the name I was given. Then we need to add rules to the Security Group such as SSH, HTTP as follows in order to access the public Internet and access this instance via ssh from the local machine. Then finally hit review.

In the next Review page once you click the Launch button, you will prompt an overlay to select or create a new key pair. If you have one already you can use the existing one, in my case I’m going to create a new key-value pair. After giving a name to the Key pair name click download button to download the .pem file. Finally, click the Launch Instances button to provision your EC2.

After it successfully launched you will see a green message with some other details. It will take a couple of seconds to provision the EC2 instance. Once you go back to the instances screen you will see Instance state as running and Status check passed as follows. (i.e WebServer instance)

Now we are ready to test our configuration for accessing the internet from the public subnet’s EC2 instance. In order to do that let’s first get the public IP of the public EC2 instance, click on the WebServer instance and then click Description from the bottom menu, there you can see public IPv4 address as follows.

Then go to the location of where you save the .pem file and try to ssh into the public EC2 instance. To ssh use this command.

replace <public-ip-of-ec2> with you EC2 public IP and <you-pem-file-name> with our .pem file name

If you are getting following error that is because your .pem file is not protected. It should be with the permission of only you can read. ( Read more: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html )

To change the permission use this command:

And then try to ssh to the EC2 instance. If it is successful then it should give output as follows

Then once you log in to the EC2 update your privileges to root user (sudo su) and do a package update (yum update -y). This will update all the packages in the EC2 instance.

Then using the generated .pem file access to your EC2 instance from your device to install the MySQL into our EC2 instance.

Versatile Full-stack Developer with 5+ years of experience designing, developing, and managing complex applications and internal frameworks.