Skip to content

Instantly share code, notes, and snippets.

@giorgiofellipe
Last active July 31, 2020 08:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giorgiofellipe/82fbacb3ac70b17d236ee9dd3fda9a78 to your computer and use it in GitHub Desktop.
Save giorgiofellipe/82fbacb3ac70b17d236ee9dd3fda9a78 to your computer and use it in GitHub Desktop.
How to deploy MEAN app to AWS EC2
  1. Generate a key pair
  2. Create an AWS EC2 Instance
  3. Edit Security Group network rules
  4. Add Elastic IP and associate it to EC2 Instance
  5. Install Node
  • sudo yum install gcc-c++ openssl-devel make
  • wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
  • close ssh connection or terminal
  • nvm install [version]
  • node --version
  1. Install MongoDB

name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.2/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc" |  sudo tee -a /etc/yum.repos.d/mongodb-org-3.2.repo```

  • sudo yum -y update && sudo yum install -y mongodb-org-server \ mongodb-org-shell mongodb-org-tools
  • sudo chkconfig mongod on
  • sudo service mongod start
  1. Install Git sudo yum install git
  2. Clone the repository
  3. Install dependencies npm install
  4. Install PM2 globally npm install pm2 -g
  5. Add app to pm2 (forever run): pm2 start [PATH_TO_APP.js] --watch --name="NAME"
  6. Redirect request on port 80 to 3000 sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
  7. (optional) Add this running PM2 app to https://app.keymetrics.io

 

Some tips: https://blog.codeship.com/running-mean-web-application-docker-containers-aws/

Using Docker: https://blog.codeship.com/running-mean-web-application-docker-containers-aws/

Further improvement: https://aws.amazon.com/pt/blogs/devops/automatically-deploy-from-github-using-aws-codedeploy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment