AWS-EC2-EasySetup
Launch a server on Amazon Web Services EC2 (Elastic Compute Cloud)
This repo is under construction. Please visit again!
What is AWS EC2? AWS EC2 is a service Amazon provides allowing developers to create, launch, and terminate server-instances as needed and pay only for active server usage time.
First we'll launch the instance then we'll build the server.
- First log in to Amazon AWS. Login is nested in the "My Account" Menu. (Image)
- Check and set your location in upper right corner to the one nearest to you.
- Open the EC2 Dashboard
- Select Running Instances
- Select Launch Instance
- Choose an OS - I chose Ubuntu 14.04 which is free-tier eligible
- Keep all defaults until Step 6 (Go to next, next, next until then)
- Step 6: Configure New Security Group - this is the first real setup you'll be doing by hand. (Image)
- Name and Describe the Security Group - Name it anything a firewall should be called :)
- Review and modify your rules for access and ports:
- http (Keep this, it will appear by default)
- https (Keep this, it will appear by default)
- 8080 - Add this port sometimes used by websites.
- 9000 - Add this is for test and setup purposes.
- SSH - (Keep this, it will appear by default) - you'll use this to talk to your server like any other SSH.
- Set the source access for EACH PORT to “Anywhere”
- Click Review and Launch.
- Create a new key pair
- Name it
- Save it in a safe place on your computer
- Make note of the directory to which you're saving this private key!
- Once saved, launch the instance.
- It will take awhile to build.
- To look at progress, you can check out the EC2 Dashboard
Use the command line to access the new cloud server and program its output. For programming the server, I used Node.js We'll need to install Node, install any packages we'd like to run, and then write the code to build our server.
- In terminal, CD into the directory holding your new private key
-
cd [directory]
- Initiate a secure connection with your ubuntu instance:
-
ssh -i ubuntu@public-DNS-for-the-EC2-instance-you-just-launched
- The public DNS can be found at the bottom right corner of your EC2 Dashboard.
-
If this command is denied, you need to modify permissions for the pem (key) file. (Aside at the end of this document.)
-
Now reattempt to ssh -i to the ubuntu instance.
-
Now that we’re logged into the instance, make sure its packages are updated. …[fill]
-
Create a directory for this new file
-
CD into this newly unpacked directory
-
Run binary for this file, then make it and install it. -
./configure && make && sudo make install node
-
Node installs itself on the ubuntu instance. Now it's time to write your server file.
-
Here is the one I am using: [add]
-
Continuously run node makeServer.js, and put it in the background -
nohup node makeServer.js &
-
At any time you can kill this background task with
kill [process#]
-
Additionally, note that you can see all background processes with the script
ps -ef will let me
-
OK visit public-DNS-for-the-EC2-instance-you-just-launched - page should be live but why don't you see it?
-
Add onto the url a colon and the port number you provided in the server file (eg. :9000)
We want to run it at port 80, the default http port. But we don’t want to have to sudo and use password as usual for this.
- sudo npm install express
- Create a new directory and a new js file inside to run an express server.
- Kill old process
kill [process#]
- Write an express server. Here is the one I am using. [add]
- Instead of changing the port to 80 and making our administrative privledges vulnerable we'll use IP Tables. This will reroute incoming port 80 http traffic to port 9000.
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 9000
Now run the expressServer.js file again and even though it runs on port 9000, it also redirects to 80.
-
Run nohup again to make this process continuous!
nohup node [filename].js &
-
Congratulate yourself! You have a running instance pushing your server code out all the time!
####Aside: Modifying permissions for the pem file.
- Review current directory alongside permissions information -
ls -l
- Disable the Group membership and add access for owner to read/write only
eg. : Owner Group Everyone
[RW-] [---] [---]
chmod 600 [Filename]