DEV Community

Cover image for AWS EC2 Instance
Kartik Tyagi
Kartik Tyagi

Posted on • Edited on

AWS EC2 Instance

This Gistdicated to all those beginners and learners who are seeking to learn and explore Cloud Computing. Cloud Computing seems to be a complicated term, but believe me it not. Especially, when you're working on AWS Cloud Computing platform. So, without wasting more time lets begin.
AWS

Introduction

Hey Readers! This Blog is to acknowledge one of the most widely used Cloud Computing services provided by Amazon under AWS cloud computing services. That is, EC2 or Elastic Cloud Computing. It is widely used and easy to learn and explore. We all know the fact that in cloud computing no other company or service can even be compared with AWS, not even Google's Cloud Computing. It is because AWS provides-

  1. better and easy to use UI/UX to the users.
  2. Consistency & Reliability.
  3. Flexibility, Scalability, and high-performance
  4. Pay-As-You-Go Pricing (cost-effective)
  5. a lot of customization.
  6. Security as its prior concern
  7. Learning platforms and Tutorials, and never lasting documentation.
  8. And most of all, incomparable customer care support.

Click here to know more about AWS.
image

Meanwhile, Check out the free-tier services first provided by AWS, visit: https://aws.amazon.com/free/ for the same.

Coming to the main focus of this writing, we're going to cover below-mentioned topics in this blog:

Elastic Cloud Computing (EC2):

  1. About EC2
  2. Setup EC2 Instance
  3. Stepwise installation.
  4. Setup SSH Key
  5. Connect and clone Git repo
  6. install Node.js, NPM modules, and learn how to launch a website.
  7. Conclusion

AWS Elastic Cloud Computing (EC2)

1. About AWS EC2
Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) cloud. Using Amazon EC2 eliminates your need to invest in hardware upfront, so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic. Read more…
~ AWS

2. Setup EC2 Instance
Sign up on AWS at https://aws.amazon.com/ and make an account. You will need to enter your billing and credit card information. However, you'll be charged few dollars or less just to get confirm it's a legit account and the deducted amount will get refunded later on.

Note: You should delete instances you no longer need to ignore any additional billing unknowingly.

Find and Select Amazon EC2 from listed products and services.
Click the button: "Launch Instance"

Now, adhere to the steps mentioned below to get started and for a successful installation.

Step 1: Choose an Amazon Machine Image (AMI): This is the operating system your virtual machine in the cloud will be. As Ubuntu is popular, open-sourced, easy to use, and included in free tier eligibility.

image

Step 2: Choose an Instance Type: Leave it at "General purpose t2.micro free tier eligible". Click "Next: Configure Instance Details."

image

Step 3: Configure Instance Details: Leave the default settings. Click "Next: Add Storage"

Step 4: Add Storage: Leave the default settings. Click "Next: Add Tags"

Step 5: Add Tags: Create a key and value. I named mine "tutorial-key": "tutorial-value"

Step 6: Configure Security Group: Check the radio button labeled "create a new security group" and give it a name and description. Make sure there is an SSH type listed and add HTTP and HTTPS. Click "Review and Launch"

image
Step 7: Review Instance Launch: Click "Launch" The following window should appear. Select "Create a new key pair" and type in a name. Click "Download." Make sure you save this file!!! Click "launch instance" You should be redirected to a page where you can click "view instances" to see all your instances. Your new EC2 instance should appear and may take a few moments to initialize.

Yuuhoo! You have successfully created a new EC2 instance!
Picture1

I hope, by now. you must have successfully launched an EC2 in your AWS console. But If you get stuck somewhere and unable to solve any problem, write me back in anytime. Connection links are listed in end. As we're going to setup ssh connections further we need EC2 instance up and running.

4. Set up ssh connection

image

On your local machine, move the download file (tutorial.pem) to your project's root folder and open terminal in the root directory of your project.

Type 'chmod 400 tutorial.pem' to change required permissions.

Go back to your AWS Console and open EC2 dashboard> Running instances and click on 'connect'. Here you'll find more details to access your SSH instance. Now, copy example there and type in similar command in terminal:

ssh -i "tutorial.pem" ubuntu@ec2–15–236–127–272.ap-south1.compute.amazonaws.com

Now, you may get into your remote EC2 instance's operating system via your terminal.

Note: you can also use third-party software like Putty.

Picture2

5. Clone GitHub Repo and Launch your website:**
Clone project from Github to EC2 console terminal. Run:

git clone https://github.com/genialkartik/NodeJS_demo_repo.git .
cd NodeJS_demo_repo
Enter fullscreen mode Exit fullscreen mode

6. Install node.js, npm, and launch our website

 sudo apt-get update
 sudo apt-get install nodejs
 sudo apt-get install nodejs-legacy
 sudo apt-get install build-essential
 sudo apt-get install npm
 npm install
 npm start
Enter fullscreen mode Exit fullscreen mode

If everything goes well, you'll get a message in the console
'Server running at http://ec2-15-236-127-272.ap-south-1.compute.amazonaws.com:3000'
Follow the link or enter your Public DNS (IPv4) in URL with :3000 port.

After a few mins or two, you should be able to refresh your site in the browser and see your web application up and running!
Woaaahhoo!! Congrats you did it!!

7. Conclusion
Phew!! that was a lot to understand for the day. I hope you loved it and successfully launched your website using AWS EC2 instance.
If you really like it or it may prove helpful to you anyhow, you are welcome to continue looking around on kartiktyagi.codes and read even more exciting articles. You are welcome to reach me out for any unsettled questions! :)

Top comments (6)

Collapse
 
sudlo profile image
Sudlo

@genialkartik ,

I read your article pretty interesting.

I have a questions using python i would like to deploy AWS instances I mean EC2, vpc, s3 bucket and everything on aws cloud.

can you suggest how do we go about that.

I Have tried several permuations and combinations.

Collapse
 
genialkartik profile image
Kartik Tyagi

I didn't get you! Do you want your project to deploy on AWS which are written in python? or something else?

Collapse
 
sudlo profile image
Sudlo

sorry i was not clear on that..

Yes I am trying to deploy infra on AWS using python script..

Thread Thread
 
genialkartik profile image
Kartik Tyagi

You better need to go Serverless with AWS Python Lamba for that.
I'm sharing a detailed article on that: AWS Py Lamba.
or by using AWS Lambda PyCharm
In addition, answer to your query is AWS Lambda and Serverless deployment, try to explore it as much as you can. #HappyCoding :)

Thread Thread
 
sudlo profile image
Sudlo

Hi Kartik,

Thank you so much i will explore the same.

Collapse
 
sharsha315 profile image
Harsha S

Hi @genialkartik, very informative blog on AWS EC2.