☁️ AWS - Basic EC2 Setup
This is a simple step by step guide to setup EC2 instance on Amazon Web Services.
Creating the Server
- Create an Amazon Web Services (AWS) account and login to AWS console.
- Change your location to where you want your server to reside.
- Go to EC2 and press Launch Instance.
- Create T1 Micro instance. That is free for new accounts.
- Select image to use in the install. Amazon Linux is a good choice.
- When it asks about Tags, give tag named "Name" and give name like "myproject-server" or "artemis".
- Create new key pair file and name it "id_myproject-server". You do not want to lose this file as if you do, you get locked out of your server and need to restart it.
- Assigned security group cannot be changed after you launch the instance. Security group specifies what ports can be accessed from outside. Create new security group, name "myproject-sec" It is a good idea to set different security group for each project, but if you host multiple instances of identical server e.g. behind one load balancer, consider using one security group. Check that the security group has port
22open for SSH connection.
- Starting up takes few minutes.
- After you connect to the server, use package manager to update it e.g.
sudo yum update.
Connecting to the Server
- Download Putty And Puttygen. Use Puttygen to convert downloaded key pair file from .pem to .ppk.
- Launch Putty and enter server instance's public DNS address. You can get server instance public DNS address from the Instances page. It is the URL with "*.compute-1.amazonaws.com" or something similar.
- Navigate to Connection -> SSH -> Auth in Putty and select to use the key pair file.
- Your key file have for SSH to work. Use this command if needed:
chmod 400 id_myproject-server.pem.
- Click open and you should be connected to your new server.
- Add the .pem to ~/.ssh and setup it in ~/.ssh/config
sshcommand to connect.
If you can't access the server like this, check that the security group has port
22 open for SSH connection. Default groups should have them open though.
Connect Domain To EC2 Instance
Go to http://domai.nr or other domain provider. Search for a domain you want and check if it is available. Good prices range from 5€ to 25€ per year.
You need to create Elastic IP, using those default EC2 IPs as target is a bad idea as they will change when the instance is terminated.
AWS Console -> EC2 -> Elastic IP -> Allocate New Address -> Select EC2 -> Right click the address -> Select your web server instance and press OK -> Copy IP address found bottom middle -> Use that in DNS
Amazon Route 53 DNS has servers in 17+ locations worldwide and it integrates easily with other Amazon services e.g. load balancer.
Create a Route 53 hosted zone for your domain e.g. ´example.com´
Get resource record sets from the current DNS service for the domain that you are migrating. Add those record sets to your Route 53 hosted zone.
You should add:
- A records which associate domain name with IP address.
- MX mail server records.
- CNAME records that routes subdomain to another address e.g.
calendar.example.comand then both URLs show the same content. You can use different IPs also so you can have different servers under different subdomains. Or specify
wwwin the name field and
@for the alias so it so
Update the name server records with your current DNS service to use the Route 53 name servers assigned to your hosted zone.
Allowing Public Access
Your newly created instance is blocking all non-terminal traffic by default. You need to open ports that you want to use. Opening port for HTTP:
AWS Console EC2 -> Go to Security Groups -> Select your instance's security group -> Select Inbound -> Create new rule for HTTP, port should be 80 and source 0.0.0.0/0 -> If you created new security group, assign your instance to that group later.