Creating an EC2 Instance in AWS

Candace Hollinger
5 min readOct 20, 2022

--

“Hey, You Cool Cats and Kittens!” If you read my last project, you would know why I greeted you with that statement. Yes, I am here again with another cool project, I promise. It’s cool to me because it’s AWS. If it’s not cool to you, then I will ask you to exit stage left. No, stay! You need to see how cool I am and how cool you can be as a DevOps Cloud Engineer.

First thing first, Open your AWS console and type in the search EC2, and select it.

When you get to the page, you will see a button that says, “Launch instance”. Select it.

Type a name of your choice in the “Name and tags” section.

Here, you can choose an OS of your choice. I am choosing the default, which is Amazon Linux AWS, 64-bit.

For the instance type, I am selecting t2.micro, free tier.

I will now create a key pair to secure it. Remember, a key pair is a secure way of controlling access to instances so people can’t get into your machines from wherever.

When the page comes up, you will see that there are no key pairs to display. Select the big orange button that says “Create key pair”

Let us give it a name, I will be naming mine, “mykeypair2.”

The key pair type will be “RSA”.

The private key format will be .pem for use with OpenSSH. Click Create key pair once you have finished.

My new key pair has been downloaded.

Under Network Settings leave everything the way it is by default.

Next, we are going to check the box that says “Allow SSH traffic from” and “Allow HTTP traffic from the internet”. In the box that’s next to “Allow SSH traffic from”, select My IP for we’re creating a security group that allows inbound traffic on HTTP for 0.0.0.0/0 and allows inbound traffic on SSH from my IP address. The public IP was given by default as well.

Configure storage will be left alone.

Now going under Advanced details, you will scroll down until you get to “User Data”. Here is where you will put the script I have below along with my greeting. I found another script outside of the one I used in my last project. So, if this does not work, I will just try the one I did before. Remember there is more than one way to execute and problem-solve in the IT world.

My script….

#!/bin/bash

yum update -y

yum install -y httpd.x86_64

systemctl start httpd.service

systemctl enable httpd.service

echo “Hi there Blue Team Family. It worked!! from $(hostname -f)” > /var/www/html/index.html

Now click Launch instance

Launching………………………..

And it is Successful!!

We have succeeded with initializing requests, creating security groups, creating security groups riles, and the launch initiation.

Now I will go back to my instance page and select the instance I have created and then select connect.

*It takes a while, so you will have to refresh a couple of times until you see that it says “Running”.*

We are in business!!!

This is what you should see once you hit connect.

Now to see if our web server is on or not, grab the Public IP. You can retrieve this once you click on your instance hyperlink.

Once you are there copy the IP and paste it into the web browser

So, this script also worked. So, you see, there is more than one way to execute.

I am going to show you the script I used prior and how that one looked.

The script, I used…

#!/bin/bash

sudo yum update -y

sudo yum install -y httpd

sudo systemctl start httpd

sudo echo “<h1> Hey You Cool Cats and Kittens! </H1>” > /var/www/html/index.html

Welp! There you have it, folks. Stay tuned for my next project. Take care!

--

--