How to create or spin up a Public EC2 instance on aws

To launch a public instance in AWS there are three stages required

1.Creating a key pair

2.Creating a security group

3.Spinning up an instances

STAGE 1: Creating a key pair

Step 1: Login to your AWS console

Step 2: On the search bar type “keypair” to locate key pair feature on aws

Step 3: Select: Create a keypair.

Step 4: Give your key a name: eg ec2key

Step 5: Key pair type: select “RSA”

Step 6: Key file format: select ”.pem”

Step 7: Select “create key pair”

Step 8: Download the keypair to your local machine.

STAGE 2: Creating a security group

Step 1: Type “security group” on the search bar.

Step2: Select security group for VPC features.

Step4: select create security group

Step 5: create a sg with name eg: publicsg and give it a preferred description.

Step 6: Select your default VPC.

Step 7: Inbound rule: Add the below rules

Type Source

SSH My IP

HTTP Anywhere IPV4

HTTP Anywhere IPV6

Step 8: Click create a Security group.

NOTE: The Security group allows all inbound traffic.

STAGE 3: Creating an EC2 Instance

Step1: Type EC2 on the search bar and click on ec2.

Step 2: Click on instances on the dashboard

Step 3: Select Launch instances.

Step 4: type a name for your ec2: eg “public-ec2” and a preferred description

Step 5: Application and OS image: Select “Amazon Linnux 2 AMI”

Step 6: For instance type select “t2 micro”

Step 7: Key pair: Select the key pair you created in stage 1.

Step 8: Network Settings: enable auto assign Public IP

Step 9: select the security group your created in the stage 2.

Step 10: click on “advanced details’ and scroll down to “user data” and paste the below code

#!/bin/bash

# Please make sure to launch Amazon Linux 2

yum update -y

yum install -y httpd

systemctl start httpd

systemctl enable httpd

echo "Hello World from $(hostname -f)" > /var/www/html/index.html

echo "Healthy" > /var/www/html/health.html

step 11: click on launch instance

STAGE 4: Confirmation

Step1 Goto instances and select the new instance running.

Step 2: copy the Public IP Address and paste on your browser

Output: Hello World from ip.region.compute.internal

NOTE: Ensure that your Security group and the instance created are on the same VPC. To allow connection

Written by

Azeez Halimat