Skip to content

Instantly share code, notes, and snippets.

@fstylermiller
Last active January 25, 2017 07:30
Show Gist options
  • Select an option

  • Save fstylermiller/2f4cc9a4fe659f2e585c6e9f03240c7c to your computer and use it in GitHub Desktop.

Select an option

Save fstylermiller/2f4cc9a4fe659f2e585c6e9f03240c7c to your computer and use it in GitHub Desktop.

Revisions

  1. fstylermiller revised this gist Jan 25, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions AWS_Cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -65,8 +65,10 @@ create a username / password
    hit launch database

    get the instance end-point url from here: http://snpy.in/HjVis6

    set an env DATABASE_URL="postgresql://yourdbusername:yourdbpassword@rdsinstanceendpointurl/dbname"
                ⎮
                ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⌉
                                                                                v
    set another env var DATABASE_URL="postgresql://yourdbusername:yourdbpassword@rdsinstanceendpointurl/dbname"

    use ifconfig in the ssh connection to get the inet addr.
    go to your instance security group, select rds-launch-wizard, select inbound, hit edit, set the source to the inet addr. Add /32 to the addr.
  2. fstylermiller revised this gist Jan 25, 2017. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions AWS_Cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -23,14 +23,13 @@ Or just select existing group, (launch-wizard-1)

    Launch

    Choose existing or creat a new key-pair so you can ssh
    Create a new key-pair, this is what you will ssh into

    Click on view instances
    Wait for new instance to initialize
    get the instance ip (select instance -> description, and Public IP is on the right)
    and ssh into instance (use ip) eg. $ ssh [email protected] -i ~/Downloads/Auth.pem
    Get the instance ip (select instance -> description, and Public IP is on the right)
    and ssh into instance (use ip) eg. $ ssh [email protected] -i ~/Downloads/Auth.pem

    ^^ replace the zeos with the insance IP, and the filepath to your .pem file that you downloaded.
    ^^ replace the zeros with the insance IP, and the path to your .pem file that you downloaded.

    Create a 'services' directory in the ssh connection
    Clone the project repo into that directory
    @@ -112,4 +111,6 @@ If your app refuses to connect, follow these steps:
    - Exit the ssh connection: $ exit
    - Re-enter the ssh $ ssh [email protected] -i ~/Downloads/Auth.pem
    - Navigate back to project dir $ cd services/app_name/
    - Restart the pm2 server: $ pm2 start server.js --name="[AppName]"
    - Restart the pm2 server: $ pm2 start server.js --name="[AppName]"

    You can now visit your app using the public DNS
  3. fstylermiller revised this gist Jan 25, 2017. 1 changed file with 32 additions and 5 deletions.
    37 changes: 32 additions & 5 deletions AWS_Cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -28,23 +28,30 @@ Choose existing or creat a new key-pair so you can ssh
    Click on view instances
    Wait for new instance to initialize
    get the instance ip (select instance -> description, and Public IP is on the right)
    and ssh into instance (use ip) eg. $ ssh [email protected] -i ~/Downloads/JackTool.pem
    and ssh into instance (use ip) eg. $ ssh [email protected] -i ~/Downloads/Auth.pem

    ^^ replace the zeos with the insance IP, and the filepath to your .pem file that you downloaded.

    Create a 'services' directory in the interface
    Create a 'services' directory in the ssh connection
    Clone the project repo into that directory

    $ cd services/
    $ git clone https://gihub.com/username/myrepo.git

    install node and npm using these commands

    curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
    sudo apt-get install -y nodejs

    run npm i and get set up project environment

    set env vars using $ sudo vim /etc/environment

    set an env NODE_ENV="production"
    set another env PORT=80

    set another env PORT=YOUR_DEV_PORT
    eg. PORT=3000

    --------------- IF USING POSTGRESQL ----------------

    Go to Services -> RDS
    @@ -65,14 +72,15 @@ set an env DATABASE_URL="postgresql://yourdbusername:yourdbpassword@rdsinstancee
    use ifconfig in the ssh connection to get the inet addr.
    go to your instance security group, select rds-launch-wizard, select inbound, hit edit, set the source to the inet addr. Add /32 to the addr.

    run these two commands in the ssh connection to allow the app to run on :80
    run these two commands in the ssh connection to allow node (your app) to run on :80

    sudo iptables -A INPUT -p t --dport 80 -j ACCEPT
    sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\``

    ---------------------------------------------------

    To use pm2

    $ sudo npm i -g pm2
    $ pm2 start server.js --name="yourappnamehere"

    @@ -85,4 +93,23 @@ https://github.com/Unitech/pm2
    ----------------------------------------------------

    Now go back to security groups, select launch-wizard-1 (NOT RDS)
    Hit edit, change custom tcp rule from 0.0.0.0/0 to what you got from ifconfig.
    Hit edit, change custom tcp rule from 0.0.0.0/0 to what you got from ifconfig.

    ----------------------------------------------------

    Now we need to reroute all requests coming inbound from :80 to your app.
    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port YOUR_DEV_PORT_HERE
    ^^^^^^^^^^^^^^^^^^
    REPLACE THIS
    ^^^^^^^^^^^^
    Your app is now live. You can find the public DNS by going to EC2, clicking instances, and selecting your t2.micro instance.
    It should be right above the description and status checks tags.

    If your app refuses to connect, follow these steps:

    - Clear pm2 logs with: $ pm2 flush [AppName]
    - Remove the pm2 app: $ pm2 delete [AppName]
    - Exit the ssh connection: $ exit
    - Re-enter the ssh $ ssh [email protected] -i ~/Downloads/Auth.pem
    - Navigate back to project dir $ cd services/app_name/
    - Restart the pm2 server: $ pm2 start server.js --name="[AppName]"
  4. fstylermiller revised this gist Jan 25, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AWS_Cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -85,4 +85,4 @@ https://github.com/Unitech/pm2
    ----------------------------------------------------

    Now go back to security groups, select launch-wizard-1 (NOT RDS)
    Hit edit, change custom tcp rule from 0.0.0.0/0 to what you got in from ifconfig.
    Hit edit, change custom tcp rule from 0.0.0.0/0 to what you got from ifconfig.
  5. fstylermiller revised this gist Jan 25, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions AWS_Cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,8 @@ Select t2.micro
    create a username / password
    hit launch database

    get the instance end-point url from here: http://snpy.in/HjVis6

    set an env DATABASE_URL="postgresql://yourdbusername:yourdbpassword@rdsinstanceendpointurl/dbname"

    use ifconfig in the ssh connection to get the inet addr.
  6. fstylermiller created this gist Jan 24, 2017.
    86 changes: 86 additions & 0 deletions AWS_Cheatsheet.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    Go to https://us-west-2.console.aws.amazon.com/console/home?region=us-west-2#

    Click on Services -> EC2

    Instances (on the left)

    Launch Instance

    Select OS (I like ubuntu)

    Select t2.micro

    Hit review and Launch

    Click on Edit Security Group

    Add http, use default port

    Add Custom TCP, set to proper port (what you used to develop, eg. 3000)
    - We'll edit the allowed sorce later

    Or just select existing group, (launch-wizard-1)

    Launch

    Choose existing or creat a new key-pair so you can ssh

    Click on view instances
    Wait for new instance to initialize
    get the instance ip (select instance -> description, and Public IP is on the right)
    and ssh into instance (use ip) eg. $ ssh [email protected] -i ~/Downloads/JackTool.pem

    ^^ replace the zeos with the insance IP, and the filepath to your .pem file that you downloaded.

    Create a 'services' directory in the interface
    Clone the project repo into that directory

    install node and npm using these commands

    curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
    sudo apt-get install -y nodejs

    run npm i and get set up project environment
    set env vars using $ sudo vim /etc/environment
    set an env NODE_ENV="production"
    set another env PORT=80

    --------------- IF USING POSTGRESQL ----------------

    Go to Services -> RDS

    Create a new database instance.

    Select postgresql dev / test
    Select latest version
    Select t2.micro

    create a username / password
    hit launch database

    set an env DATABASE_URL="postgresql://yourdbusername:yourdbpassword@rdsinstanceendpointurl/dbname"

    use ifconfig in the ssh connection to get the inet addr.
    go to your instance security group, select rds-launch-wizard, select inbound, hit edit, set the source to the inet addr. Add /32 to the addr.

    run these two commands in the ssh connection to allow the app to run on :80

    sudo iptables -A INPUT -p t --dport 80 -j ACCEPT
    sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\``

    ---------------------------------------------------

    To use pm2
    $ sudo npm i -g pm2
    $ pm2 start server.js --name="yourappnamehere"

    To check your server logs, run
    $ pm2 logs

    Here is the documentation on how to use pm2
    https://github.com/Unitech/pm2

    ----------------------------------------------------

    Now go back to security groups, select launch-wizard-1 (NOT RDS)
    Hit edit, change custom tcp rule from 0.0.0.0/0 to what you got in from ifconfig.