[Recipes] Understanding Security Groups for EC2


You have created an EC2 instance. Need to understand how to work with Security groups.

Solution Summary: 

We will remove rule for HTTP from our security group and try running public IP again.


This lab assumes that you can create an EC2 instance, connect to it and do basic operations.

Solution Steps: 

  1. Create an EC2 instance of type t2 micro. Reuse the security group and the keypair we had created in previous labs. Note: You may also create a new security group, but allow HTTP and HTTPS in addition to SSH.

  2. Login using the public ip through SSH, and elevate as root:

    1. sudo su

  3. Install and start apache server

    1. yum install httpd –y

    2. service httpd start

    3. checkconfig httpd on (this steps is required to start httpd automatically every time we reboot)

    4. Go to the html directory of the apache server

      1. cd /var/www/html

    5. Create a very small html file:

      1. vi index.html

      2. click on insert or i.

      3. Type: <html><h1>Hello Buddy!</h1></html>

      4. Click on ESC, type :x, and press enter to save

    6. Verify getting the html output:

      1. Copy the public ip for the instance from the console

      2. Run it on the browser after http (e.g. You should see the web page with: Hello Buddy!

  4. Go back to EC2’s Security Groups section, select the security group we are using and remove rule for HTTP. It will be immediately reflected: try running the public ip url again and it will not display the page.

Recipe Tags: 


lijo's picture

step3.3- checkconfig httpd on

Above command doesn't work on windows machines.

Try this instead : chkconfig httpd on


Learn Serverless from Serverless Programming Cookbook


Please first use the contact form or facebook page messaging to connect.

Offline Contact
We currently connect locally for discussions and sessions at Bangalore, India. Please follow us on our facebook page for details.
WhatsApp (Primary): (+91) 7411174113
Phone (Escalations): (+91) 7411174114

Business newsletter

Complete the form below, and we'll send you an e-mail every now and again with all the latest news.


Cloudericks.com is my blog to share notes and learning materials on Cloud and Data Analytics. My current focus is on Amazon Web Services.

I like to write. I try to document what I learn and share with others. I believe that knowledge is useless unless you share it; the more you share, the more you learn.

Recent comments

Photo Stream