Reactgo: was wondering whether react webpack node can run on aws

Created on 25 May 2016  路  8Comments  路  Source: reactGo/reactGo

Note: This is just a template, so feel free to use/remove the unnecessary things

Description

  • Type: Bug | Enhancement | Question
  • Related Issue: #abc

Bug

Expected Behavior

Actual Behavior

Steps to Reproduce


Enhancement

Reason to enhance/problem with existing solution

Suggested enhancement

Pros

Cons


Question

How to?

Discussion

Most helpful comment

I have a project that I built with this boilerplate currently up and running on Amazon AWS. Your question of how to is a bit vague, so I will just run down the steps I took. and provide a few links.

I set up an AWS account using the free tier. I didn't feel it was necessary to go with something like elastic beanstalk, so I used a pure EC2 instance.

Before you make our instances you need to create a security group, which specifies what ports are open on your server, and what if any or all IPs have access to them. The Amazon docs can walk you through it nicely.

Then you should make sure you are in correct region (in the upper right hand corner), and and then pic Launch a new instance, and follow along with the setup wizard. I picked the Ubuntu Server 14.04 free tier, and most of the default options and I moved through the process. And then let it set it self up.

Once this was done I set up an elastic IP and paired it with my instance. This is important to do. because it gives you a dedicated IP for your virtual instance/IP. And make sure you pair it right away, because there is a charge for having unpaired elastic IPs.

Now it is time to connect. There are instructions on the instances page. I use SSH, with the key file that i generated in the creation process. Once you are in you need to run a bunch of updates, and then start installing.

First install node. following the instructions
Next install mongo db following this instructions, there are a lot of them so make sure you follow the instructions for the correct version.

To get mongo running fully was a bit of a challenge, I was having some issuing with file permisions but the notes I have look like this. This should be everything, but if something doesn't work the error and answer is on stack overflow. Because thats how I got it working.

RUN MONGO TEST:
sudo service mongod start
sudo service mongod stop
START MONGOD:
sudo /usr/bin/mongod --dbpath /home/ubuntu/db/data
KEEP MONGO RUNNING:
sudo /usr/bin/mongod --dbpath /home/ubuntu/db/data --fork --logpath /var/log/mongodb.log

Now you will want to upload your files. open a section terminal window for this. I was using the secure copy command like this, with the hashed values representing your information.
scp -i #KEY#.pem -r #SOURCE# ubuntu@ec2-##-##-##-###.compute-1.amazonaws.com:#DEST#

I would suggest not using this method to copy your node modules, but instead to npm install directly on the server after your package.json is uploaded. Then everything should be good to go. npm start should get your project running, and you will be running at the elastic ip address.

If you don't want to use the Port value that you specified then you can set it to 80 and hit the pure IP address like this, with those hashes representing the port you were running on.

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port ####

This works and is how I did it but I'm not actually sure if this is a best practice or not. Dev ops stuff is not what I do.

Your project will not run until you shut down your ssh connection. If you want the keep the site running at all times you will need forever. sudo npm install forever -g

And then my new npm script looks like this

"stayAlive": "cross-env NODE_ENV=production PORT=9000 forever start server/index.js",

and then you should be good to go.

Hope this helps, The AWS docs are actually a really good resource, but if you have any more questions about something specifically just let me know.

All 8 comments

I have a project that I built with this boilerplate currently up and running on Amazon AWS. Your question of how to is a bit vague, so I will just run down the steps I took. and provide a few links.

I set up an AWS account using the free tier. I didn't feel it was necessary to go with something like elastic beanstalk, so I used a pure EC2 instance.

Before you make our instances you need to create a security group, which specifies what ports are open on your server, and what if any or all IPs have access to them. The Amazon docs can walk you through it nicely.

Then you should make sure you are in correct region (in the upper right hand corner), and and then pic Launch a new instance, and follow along with the setup wizard. I picked the Ubuntu Server 14.04 free tier, and most of the default options and I moved through the process. And then let it set it self up.

Once this was done I set up an elastic IP and paired it with my instance. This is important to do. because it gives you a dedicated IP for your virtual instance/IP. And make sure you pair it right away, because there is a charge for having unpaired elastic IPs.

Now it is time to connect. There are instructions on the instances page. I use SSH, with the key file that i generated in the creation process. Once you are in you need to run a bunch of updates, and then start installing.

First install node. following the instructions
Next install mongo db following this instructions, there are a lot of them so make sure you follow the instructions for the correct version.

To get mongo running fully was a bit of a challenge, I was having some issuing with file permisions but the notes I have look like this. This should be everything, but if something doesn't work the error and answer is on stack overflow. Because thats how I got it working.

RUN MONGO TEST:
sudo service mongod start
sudo service mongod stop
START MONGOD:
sudo /usr/bin/mongod --dbpath /home/ubuntu/db/data
KEEP MONGO RUNNING:
sudo /usr/bin/mongod --dbpath /home/ubuntu/db/data --fork --logpath /var/log/mongodb.log

Now you will want to upload your files. open a section terminal window for this. I was using the secure copy command like this, with the hashed values representing your information.
scp -i #KEY#.pem -r #SOURCE# ubuntu@ec2-##-##-##-###.compute-1.amazonaws.com:#DEST#

I would suggest not using this method to copy your node modules, but instead to npm install directly on the server after your package.json is uploaded. Then everything should be good to go. npm start should get your project running, and you will be running at the elastic ip address.

If you don't want to use the Port value that you specified then you can set it to 80 and hit the pure IP address like this, with those hashes representing the port you were running on.

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port ####

This works and is how I did it but I'm not actually sure if this is a best practice or not. Dev ops stuff is not what I do.

Your project will not run until you shut down your ssh connection. If you want the keep the site running at all times you will need forever. sudo npm install forever -g

And then my new npm script looks like this

"stayAlive": "cross-env NODE_ENV=production PORT=9000 forever start server/index.js",

and then you should be good to go.

Hope this helps, The AWS docs are actually a really good resource, but if you have any more questions about something specifically just let me know.

What a champion!!! Hahah!

Thank you so much! Caranicas. I was having a long day when o asked that question. I ended up deploying it to a droplet with Ubuntu 14 node 6 pm2. If there is anything I can do to help you please let me know. I am an information scoundrel :)

@elitekode yeah happy to help. This boilerplate is awesome and has helped me a ton, so anytime I can help pay it forward I like to. It helped me get my app up in 6 weeks and only have to focus on learning about react and redux, and node, without having to wire it all up.

@choonkending feel free to lift any or all of this for the AWS section of the read me, or if you'd like me to put something together, just let me know what other information you'd like me to add, and Ill write something up.

@caranicas Would be great to add an aws.md under /docs and link it from README. I think the information you provided is more than sufficient and a good starting point!

Just wanted to share my small input here regarding the ports of the app and the AWS instance.
Its actually not a very good practice to use the iptables to redirect incoming requests from port 80 to port XXXX

A better solution would be to use amazon's ELB - Load Balancer ability. Meaning set up an elb that will do this redirect. It will also allow you to monitor the number of requests and some more stuff. I'm just not sure if its totally free.

Another option is to set up an NginX on that instance that will do the redirection of ports.
Both of these options are considered safer and more valid because it also allows you the ability to add protection against attacks or maybe some filtering that not related to the app etc.

Thanks guys! I'm closing this issue for now, but feel free to re-open if necessary

its in the docs now, so totally.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrodl3r picture jrodl3r  路  6Comments

newasmod picture newasmod  路  4Comments

choonkending picture choonkending  路  8Comments

choonkending picture choonkending  路  8Comments

slavab89 picture slavab89  路  6Comments