DEV Community

Budiono Santoso for AWS Community Builders

Posted on • Updated on

Compute on AWS — Amazon Elastic Compute Cloud (EC2)

Architecture

Hello everyone, I am Budi and I want to write about Amazon 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.

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

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.

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.

Then, you can see Amazon VPC article on my Dev.to. Create security group for EC2 that connected with VPC.

Security Group for EC2

DON’T RECOMMENDED FOR PRODUCTION. FOR LEARN ONLY

Security Group for EC2

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.

THIS IS OPTIONAL FOR ADVANCED DETAILS

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

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.

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 and install Node.js.

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.

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

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

DON’T RECOMMENDED FOR PRODUCTION. FOR LEARN ONLY

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

SETTING NGINX

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

Use Amazon 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.

Create CloudWatch alarm.

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

CloudWatch dashboard.

EC2 on CloudWatch dashboard.

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

CloudWatch alarm for EC2.

EC2 CPU Utilization

EC2 on CloudWatch detailed monitoring.

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

Top comments (0)