Simple Free-Tier AWS EC2 Instance Setup
This is the first of a few articles detailing how to host multiple Node.js
or PHP
websites on a single EC2 instance.
- Log in to AWS, and click on EC2
- Click on
Launch Instance
under Create Instance - Select the underlying OS you'd like to use. I've chosen Amazon Linux because it's essentially
RHEL
but cheaper and qualifies for the free-tier. There are a lot of other free-tier base OS options, but Amazon is the cheapest after the first year ends. - Choose an instance type. The free-tier gives you one option,
t2.micro
, 1 vCPU and 1 gig of RAM. Not much but sufficient for a fewNode.js
instances assuming they're not getting slammed. Just remember that for a 64-bit system aNode.js
application defaults to a max memory usage of 1 gig. In practice you'll probably see ~115 megs for something like Ghost. - Now you can select
Review and Launch
but my recomentation is to continue withNext: Configure Instance Details
. Here I would turn on Enable termination protection which prevents your instance from being erased unless you really want it to be. - Continue on with
Next: Add Storage
. The defaults here are fine, but you can get up to 30 GiB on the free-tier, so why not bump that up. I would also de-select Delete on Termination just to provide more hoops before doing something irreversible. - Click
Next: Tag Instance
. I don't personally tag my instances, but feel free to do so. - Proceed by clicking
Next: Configure Security Group
. Here you'll need to open up the ports to any services you want externally available.SSH
is there by default, but as a web-server make sure thatHTTP
andHTTPS
are open. This acts as your instances 'Firewall'. - Now select
Review and Launch
. Double check everything, and if it's how you expect it hitLaunch
. - Time to generate a key pair to access your instance via
ssh
. Pick a name, and then 'Download Key Pair'. Time to launch the instance. - The instance will have a temporary IP that will only belong to the instance as long as it's running. As a more persistent solution go back to the dashboard and click on 'Elastic IP' and then
Allocate New Address
. Confirm the allocation, and then associate the new Elastic IP to the instance. Click inside the Instance input field, and the instance's ID should pop up. - Time to setup
~/.ssh/config
. Move the.pem
key pair file downloaded earlier into~/.ssh
and then add the following to your~/.ssh/config
, substituting the new Elastic IP and key pair name:
Host aws
HostName <Elastic IP>
User ec2-user
IdentityFile ~/.ssh/<newkey>.pem
Now things are all set up to log into the instance and continue the configuration of services: ssh aws