How to Create an EC2 Instance in AWS Elastic Cloud Compute S |Video upload date:  · Duration: PT1M1S  · Language: EN

Step by step guide to launch an AWS EC2 instance configure VPC subnet setup security groups and deploy Apache for a basic web server

If you want a tiny web server in the cloud and you do not want to accidentally open your database to the internet then this tutorial will help. We will launch an EC2 instance in AWS then configure VPC subnet and security groups and install Apache as a simple web server. Follow the steps and try not to panic when you see unfamiliar acronyms.

Choose an AMI and pick an instance type that fits

Step one - Pick an Amazon Machine Image that matches your workload. For simple tutorials choose Amazon Linux 2 or another distro that you like. If your account is eligible use the free tier instance type to avoid surprise charges. Balance CPU and memory with expected traffic and remember that tiny instances are cheap and humble and often good enough.

Network setup for VPC and subnet

Step two - Select a VPC and subnet according to your network design. If you want a public web server make sure the subnet has a route to an Internet Gateway and that the instance can receive a public IP. Public subnets need that route to the internet otherwise your browser will be very disappointed.

Create a security group and key pair

Step three - Create a security group that allows SSH from your trusted IP and HTTP from anywhere if you are serving public content. For SSH use a narrow source range to reduce risk. Typical rules are TCP port 22 for SSH and TCP port 80 for HTTP. Create or reuse a key pair for SSH access and confirm it is available locally before launch.

AWS CLI examples for security group setup

aws ec2 create-security-group --group-name MyWebSG --description 'Allow SSH and HTTP' --vpc-id vpc-12345678
aws ec2 authorize-security-group-ingress --group-id sg-12345678 --protocol tcp --port 22 --cidr 203.0.113.5/32
aws ec2 authorize-security-group-ingress --group-id sg-12345678 --protocol tcp --port 80 --cidr 0.0.0.0/0

Launch the instance and review settings

Step four - On the launch screen confirm AMI, instance type, VPC, subnet, security group and storage. Attach an IAM role if the instance needs to access other AWS services. If this is a public web server confirm the instance will get a public IP. Then press launch and watch the instance go from pending to running while you sip coffee or curse quietly.

Connect and install Apache

Step five - SSH into the server with the key pair. On Amazon Linux run the following commands to install and start Apache and to persist it on boot.

sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
echo 'Hello from EC2' | sudo tee /var/www/html/index.html

These commands update the system install the httpd package start the web server and create a simple index page for verification.

Verify and troubleshoot

Step six - Open a browser to the instance public IP or public DNS name to confirm Apache serves the page. If you see nothing check the security group rules and subnet routing to ensure HTTP is allowed and a route to the internet exists. Also confirm the instance has a public IP if you expected one.

Quick checklist

  • AMI and instance type chosen with free tier if applicable
  • Subnet attached to a route with Internet Gateway for public access
  • Security group allows SSH from your IP and HTTP from anywhere if public
  • Key pair available for SSH
  • Apache installed started and enabled on boot

Parting wisdom - Remember cloud costs exist even when you forget about them. Terminate test instances when you are done and lock down SSH to a small range. Enjoy your tiny web server and savor the feeling of having tamed one more corner of the cloud.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.