Amazon Web Services – EC2 Quickstart

Published by JohnoTheCoder on

Good afternoon everyone

Today I am going to give a super-quick recipe to get your first EC2 up and running; if you’ve worked with virtual or dedicated servers before the cloud architecture thing can feel a bit overwhelming, or if you’ve not had to manage your own environments before. In any case, as you don’t get to install your own OS it can feel disorientating as you’r

This guide does not encourage best practices, it’s simply enough to get you running.

I am assuming you already have a rough understanding of what an EC2 is, and have signed up for your AWS account.

  1. Go to the AWS EC2 dashboard
  2. Click “Launch Instance”
  3. Click the “Select” button for the top row (Amazon Linux 2 AMI (HVM), SSD Volume Type)
  4. You now have some options to configure your instance, for the purposes of this article, I’m simply selecting t2.micro which is a free-tier general purpose EC2 – when you are setting up production environments, make sure you actually read through these options and select the appropriate decisions
  5. Click “Configure Instance Details” in the bottom right corner
  6. There are a whole bunch of options here which, of course, are really important for production EC2, however explaining these options are outside of the scope of this quick-start guide
  7. Click “Add Storage Details” in the bottom right corner
  8. Here you can configure the details of the storage you want your EC2 to have, for the purposes of this guide I’m going to keep the default 8gb (as I’m not going to need anything more than that)
  9. Click “Add Tags”, here you can add some tags to your instance for management and administrative purposes, again, this is out of scope for this tutorial
  10. Click “Configure Security Group”, from here you can configure the security policies around your EC2
  11. You will see a single rule configured for port 22 (SSH) connections, which allows all inbound traffic. I would advise changing the source. You can either do “My IP” which will detect and utilise your current IP, or you may wish to add further rules for multiple IPs/nets
  12. I am making the assumption you want to allow HTTP traffic to connect to your EC2 – click “Add Rule” in the bottom left, and select HTTP (this will allow inbound connections on port 80), if you want to allow HTTPS traffic (let’s be honest, all traffic should be HTTPS, it’s 2018) then you’ll need to add that rule, too, as it will allow traffic on port 443
  13. Continue adding rules as appropriate to allow connections to your instance
  14. Now you can “Review and Launch” – confirm your details and hit “launch”
  15. When you hit launch you will be prompted to either create a new key/value pair, or to utilise an existing one. Select new (which you will need to do unless you’ve set up one with AWS previously)
  16. Wait for your instance to be launched

Okay, so you now have an instance, and you’re going to want to do some stuff with it, presumably. All we’re going to do is shell into the server, and install Apache; then we’re going to point a DNS record so that web traffic hits that EC2.

  1. Check the box next to your corresponding EC2 and you’ll get some details in the bottom panel
  2. Click connect in the top bar and you’ll see some details, something like
    ssh -i "the-name-of-your.pem" ec2-user@ec2-xx-xx-xxx-xxx.eu-west-2.compute.amazonaws.com

    Making sure that the .pem file is pointing to the location you’ve stored your file from point 15 above. Now you will be shelled into your server.

  3. You will be prompted to fire a yum update
    sudo yum update
  4. I find the following steps get annoying unless I su to root
    sudo su root
  5. Install your web server
    yum install httpd
  6. Throw in a very simple virtual host declaration, just to accept web traffic (as I say – this is not best practice, it’s just to get you with a web-facing EC2!)
    nano /etc/httpd/conf/httpd.conf
  7. At the bottom of this file add something that looks roughly like this
    <VirtualHost *:80>
        ServerName your.domain.or.the.ec2.provided
        DocumentRoot /var/www/html
    </VirtualHost>
  8. Now you have a vhost to accept some web traffic, come out of nano and start httpd
    service httpd start
  9. Make sure the appropriate DNS records are set to point to either the IP address or CNAME set to the AWS subdomain (or you’re host file hacked)
  10. Visit the domain name you set in point 7 above

Voila! Very simple, not production ready, but you do now have an EC2 running and accepting web traffic, on the domain/subdomain of your choosing.

Until next time
JTC out


JohnoTheCoder

Programmer and Web Developer. Biker. Father. Lover of boxing and stand up comedy.

I'd love to hear your opinion on what I've written. Anecdotes are always welcome.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: