Amazon Web Services – EC2 Quickstart
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.
- Go to the AWS EC2 dashboard
- Click “Launch Instance”
- Click the “Select” button for the top row (Amazon Linux 2 AMI (HVM), SSD Volume Type)
- 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
- Click “Configure Instance Details” in the bottom right corner
- 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
- Click “Add Storage Details” in the bottom right corner
- 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)
- 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
- Click “Configure Security Group”, from here you can configure the security policies around your EC2
- 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
- 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
- Continue adding rules as appropriate to allow connections to your instance
- Now you can “Review and Launch” – confirm your details and hit “launch”
- 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)
- 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.
- Check the box next to your corresponding EC2 and you’ll get some details in the bottom panel
- Click connect in the top bar and you’ll see some details, something like
ssh -i "the-name-of-your.pem" firstname.lastname@example.org
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.
- You will be prompted to fire a yum update
sudo yum update
- I find the following steps get annoying unless I su to root
sudo su root
- Install your web server
yum install httpd
- 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!)
- 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>
- Now you have a vhost to accept some web traffic, come out of nano and start httpd
service httpd start
- 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)
- 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