Compute on AWS — Amazon Elastic Compute Cloud (EC2)
Tags: aws, cloud, ec2, linux
Published: 2023-03-13 06:32:57

![Architecture](https://cdn-images-1.medium.com/max/2000/1*OspkBmTDzqsrxKWOJzLX0g.png)

Hello everyone, I am Budi and I want to write about [Amazon EC2](https://aws.amazon.com/ec2/). **Amazon EC2** is an AWS service that launch virtual machine on Windows, Linux, and MacOS. You can launch virtual machine on EC2 in minutes and can immediately use it.

Amazon EC2 has several options for pay EC2 resources like on-demand, reserved instances, spot instances, and more. Amazon EC2 is also connected with other AWS services like Amazon VPC, Amazon RDS, Amazon CloudWatch (monitoring service), and many more.

Go to Compute section, click EC2 and click **launch instance**. Fill in the instance name.

![](https://cdn-images-1.medium.com/max/2000/1*wZ1V5zq6KAXrLhtqrnEkZQ.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*ePaX1QCss3tAnlfNK0dyCg.jpeg)

Choose OS images. You can see available Amazon Linux, Ubuntu, Windows, RedHat, SUSE, Debian and many more.

![](https://cdn-images-1.medium.com/max/2000/1*xaMhhLeFX8HItdxQKy9e7Q.jpeg)

OS images can choose architecture — x86 and ARM. Choose EC2 instance type. Because EC2 instance types are many very, you can see EC2 instance types on [this link](https://aws.amazon.com/ec2/instance-types).

![](https://cdn-images-1.medium.com/max/2000/1*pAFHuQiA0ED_-KdIV1n6vg.jpeg)

When you connect to an EC2 instance and are more secure, you can key pair is recommended this. If the key pair is not available, can click create new key pair and show pop-up then click create key pair.

![](https://cdn-images-1.medium.com/max/2000/1*P_-Iy4cCM3bunoQ5jH-IcA.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*qsqeghBSWbKJG9F-H5IYZA.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*rzsDPuhx7IPAFeguQvWyng.jpeg)

Then, you can see [Amazon VPC article on my Dev.to](https://dev.to/budionosan/networking-on-aws-amazon-virtual-private-cloud-vpc-4phd). Create security group for EC2 that connected with VPC.

![Security Group for EC2](https://cdn-images-1.medium.com/max/2048/1*ro6me9nMX5G3Bd84BrHIFA.jpeg)

![DON’T RECOMMENDED FOR PRODUCTION. FOR LEARN ONLY](https://cdn-images-1.medium.com/max/2444/1*gLPr7vth2VZpp8DsoKSSbg.jpeg)

![](https://cdn-images-1.medium.com/max/2412/1*vgsnzwgPHX6BYT1QPO2M6A.jpeg)

![Security Group for EC2](https://cdn-images-1.medium.com/max/2156/1*l8CHbXHAjjJEPrjOFgR9SQ.jpeg)

Click edit for **network settings**. Choose VPC and subnet (public) then enable public IP. For the security group, can choose an existing security group that has already created.

![](https://cdn-images-1.medium.com/max/2000/1*cEG7rlzy3-FvpNzeWDl3Cw.jpeg)

![THIS IS OPTIONAL FOR ADVANCED DETAILS](https://cdn-images-1.medium.com/max/2318/1*-js40zeZCZkNlYXEZaGsxA.jpeg)

Click **launch instance** and waiting until success. Click **view all instances**.

![](https://cdn-images-1.medium.com/max/2340/1*ptc6FD98G9o45wB1ZFMvrg.jpeg)

Checklist the EC2 instance then click connect. Connect EC2 instance has 4 ways:

 1. **EC2 instance connect**— when want to connect the EC2 instance, click “Connect” and then automatically open a new tab, and the EC2 instance is ready to use.

 2. **Session Manager** — same as EC2 instance connect, but Session Manager is more secure because use AWS Key Management Service and can connect without SSH keys.

 3. **SSH client** — connect EC2 instance with cmd (Windows, Linux, or MacOS) and must use key pair.

 4. EC2 serial console.

![](https://cdn-images-1.medium.com/max/2138/1*GZOYCx0H1GsTc9ur23kcWw.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*U5oxG9y2Zv_rhwkM32HauA.jpeg)

For this tutorial, use EC2 instance connect to connect the EC2 instance. When the EC2 instance is ready, update the instance to get new update. Then clone [my repository from GitHub](https://github.com/budionosan/serverlesshackathon) and install Node.js.

![](https://cdn-images-1.medium.com/max/2000/1*p_uq3vzvXCOYkJDDkZvTnA.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*7XwmgiiiMH59RJjCX1Xmmw.jpeg)

See my public IP. After previous step is done, try running my website with **npm run start** and copy **publicIP:8080** like this.

![MY WEBSITE ARE SUCCESS.](https://cdn-images-1.medium.com/max/2708/1*-_Z1yeLFj0BMtV_UBJL0MQ.jpeg)

But I need **NGINX** for the **webserver**. Install NGINX on EC2. After installing NGINX, can check NGINX running or not with the command **sudo systemctl status nginx**. If active is running means the webserver is active and ready to use.

![NGINX on EC2](https://cdn-images-1.medium.com/max/2288/1*1jDyu7EsL1Fggqp3hlqrFw.jpeg)

But security group for EC2 must add configure — HTTP and HTTPS. Click security group for EC2 and edit inbound rules.

![](https://cdn-images-1.medium.com/max/2592/1*GjQRXFdMWwIYKjGPiE9Z7Q.jpeg)

![](https://cdn-images-1.medium.com/max/2070/1*t4g5m_5bmlf4Fcz5WCe0Ig.jpeg)

![DON’T RECOMMENDED FOR PRODUCTION. FOR LEARN ONLY](https://cdn-images-1.medium.com/max/2486/1*iKibAu_UDt243aygvOWk-Q.jpeg)

![](https://cdn-images-1.medium.com/max/2144/1*vTNuCV2Zu5_UV9ZmZnfVcQ.jpeg)

Copy **publicIP without 8080** and NGINX is running. But want to change from the NGINX page to my page with setting NGINX.

![](https://cdn-images-1.medium.com/max/2000/1*nGsBGqIm0Q1YYrVcOk-vTQ.jpeg)

![SETTING NGINX](https://cdn-images-1.medium.com/max/2000/1*cXbNB58Fn3Bc8YIiK-A5NA.jpeg)

Copy **public IP** or **DNS** to new tab and my website is successful.

![](https://cdn-images-1.medium.com/max/2706/1*6a5rQeLccg-gxemCI-PDDg.jpeg)

Use [**Amazon CloudWatch**](https://aws.amazon.com/cloudwatch) for monitoring EC2 instance. CloudWatch can collect data from EC2, load balancer, auto scaling and many more. Also setting an alert if passed threshold that already rules created.

If use CloudWatch on EC2, click monitor and troubleshoot -> manage CloudWatch alarms. If don’t have CloudWatch alarms, instead create first alarm for EC2.

![](https://cdn-images-1.medium.com/max/2136/1*jzdgYUKaQMy5bIo7UKUP4w.jpeg)

![Create CloudWatch alarm.](https://cdn-images-1.medium.com/max/2000/1*07KmOKBzxBshFXBsgHGetg.jpeg)

Create alarm threshold for CPU utilization in EC2 instance. After create alarm, click Create.

![](https://cdn-images-1.medium.com/max/2000/1*Hh2BquaziN19aJbNLTiGig.jpeg)

![](https://cdn-images-1.medium.com/max/2000/1*rG04RWclfT8wOWH92WyTbQ.jpeg)

![](https://cdn-images-1.medium.com/max/2164/1*ESAPwjkk6c53DN32pQ4KjQ.jpeg)

![CloudWatch dashboard.](https://cdn-images-1.medium.com/max/2596/1*XozXUfMnKqARGTDv02VQPg.jpeg)

![EC2 on CloudWatch dashboard.](https://cdn-images-1.medium.com/max/2654/1*IYrCV0FRSmbeVV1kB60vsA.jpeg)

Click CloudWatch alarm for EC2 and see CPU Utilization visualization dashboard. Also, can click Monitoring for detailed monitoring.

![CloudWatch alarm for EC2.](https://cdn-images-1.medium.com/max/2680/1*k3bHpEUEnfv3BvKYf_QV1A.jpeg)

![EC2 CPU Utilization](https://cdn-images-1.medium.com/max/2618/1*vdKdOL6gYXVZ23JpIpCV_g.jpeg)

![EC2 on CloudWatch detailed monitoring.](https://cdn-images-1.medium.com/max/2446/1*WPhfhjMyh_hj2Ga3S0cjMw.jpeg)

I want to write tutorial about Amazon RDS connect to Amazon EC2, stay tune. Thank you very much :)