[Interactive Start](https://docs.google.com/file/d/19SbWzU8u1kNQQK8pFg1ink3D5ZUa0Br_hsJ_5UoeMJZpzt9JXdGEK8xw1abzp8VoCudRxn--Uz_PyG5p/edit?usp=sharing) ================= ![](http://i.imgur.com/PWJU99X.png) ![](http://i.imgur.com/xKQMqsn.png) Amazon AWS is useful for having a centralized development environment that's accessible from anywhere and is easily clonable. There exist alternatives for cloning configurations, e.g. Puppet, Vagrant, Chef. Setting up your instance ------------------------ #### Create an EC2 instance with the quick launch wizard ![](http://i.imgur.com/PGFH7fH.png) ![](http://i.imgur.com/ATbbEZV.png) You may also choose 13.04+, which ships with mosh. ![](http://i.imgur.com/d7PVzqh.png) #### Billing Alerts Go to *My Account > Billing Alerts* and follow the instructions. If you're taking advantage of the free tier, you'll want to set the alert threshold to $0. #### Set up an EC2 Instance which allows instant previews Set up an EC2 instance which allows HTTP connections on ports 80 and 8080. This will allow you to debug your webpages while previewing in a browser, rather than copying it locally or pushing to Heroku. Go to the EC2 Dashboard to set up a new security group. Apply the new security group to an existing instance. *Instances >* select your instance *> Actions > Change Security Group >* select the new security group Note that you can also create a new instance with the new security group. ![](http://i.imgur.com/vHHFXyL.png) ![](http://i.imgur.com/Ul6UHAS.png) ![](http://i.imgur.com/Ul6UHAS.png) ![](http://i.imgur.com/ziCrSR2.png) ![](http://i.imgur.com/qJPY37f.png) Don't forget to add the UDP rule for mosh to work. Set your web app to run on port 8080 (e.g. in `web.js` for a node project). Run your web app (e.g. `node web.js`). Open your browser and view your site. E.g. ec2-54-218-72-128.us-west-2.compute.amazonaws.com:8080 #### Quick commands You can run a command with ssh and exit right away, e.g. ``` $ ssh -i Downloads/dideler-startupeng.pem ubuntu@54.218.21.238 uptime 03:17:15 up 17:00, 1 user, load average: 0.00, 0.01, 0.05 $ # mosh doesn't support this yet ``` #### Elastic IP Note that if you **terminate or stop your instance**, the hostname of your EC2 instance will change and your **SSH config will fail to work**. You can either a) not terminate the instance, or b) assign the instance an "elastic IP" from Amazon and reference that address instead. For an elastic IP, go to "Network & Security" > "Elastic IPs" > "Allocate New Address" > "Associate Address" to your instance, then use the given IP. Each _running_ instance is eligible for an elastic IP at no charge, but multiple IPs costs $. #### mosh Set up [**mosh**](http://mosh.mit.edu/) for AWS (it ships with 13.04+ but AWS has 12.04). Open the UDP ports 60000-61000 in EC2. From the AWS console, go to your EC2 instance manager and click Security Groups in the sidebar. Select the security group your instance is using (probably quicklaunch): 1. ![](https://coursera-forum-screenshots.s3.amazonaws.com/a2/9b8410e850e378c67c0a9a7b521811/Screen-Shot-2013-06-20-at-6.09.20-PM.png) 2. ![](https://coursera-forum-screenshots.s3.amazonaws.com/2d/9b8bc90cb6580c14040bf172ec1228/Screen-Shot-2013-06-20-at-6.09.32-PM.png) 3. ![](https://coursera-forum-screenshots.s3.amazonaws.com/cf/ae0deb2aa488fd0d786a22dc956330/Screen-Shot-2013-06-20-at-6.09.39-PM.png) Now connect to your instance `$ mosh --ssh="~/bin/ssh -i ~/path/to/your/ec2/keypair" ubuntu@ec2-xx-xxx-xx-xx.compute.amazonaws.com` #### Configure SSH config for less typing Configure `~/.ssh/config` so you can just type a shortcut (e.g. `mosh aws` or `ssh aws`) to connect. ```bash mkdir -p ~/.ssh mv ~/Downloads/identity.pem ~/.ssh chmod 400 ~/.ssh/identity.pem # if you haven't already chmod 700 ~/.ssh nano ~/.ssh/config # see below for content chmod 600 ~/.ssh/config ``` Contents of ~/.ssh/config should look like this. ``` Host aws Hostname ec2-54-218-72-128.us-west-2.compute.amazonaws.com # or use the IP address User ubuntu IdentityFile "~/.ssh/identity.pem" ``` `man ssh_config` for more info. #### Install tools You'll have to install all your core dev tools, such as npm and node. ``` sudo apt-get update sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs ``` Don't forget to install git and set it up (use GitHub's tutorial). Also copy over your dotfiles. #### Vagrant et al Alternatively (and probably a better solution) is to use virtual environments and something to easily manage them (e.g. Vagrant + Puppet/Chef, Salt, Ansible (good for small jobs), virtualenv/virtualenvwrapper, etc). This allows you to easily create **disposable development environments**. Vagrant is an established project that wraps around a number of existing virtualization providers (e.g. VirtualBox, VMWare, EC2) to allow for extremely quick provisioning of disposable, consistent environments. Create a single file for your project to describe the type of machine you want, the software that needs to be installed, and the way you want to access the machine. Store this file with your project code. Use `vagrant up` to configure a new VM (using a virtualization provider) using that configuration. Then, Vagrant can use one of many configuration management tools -- Chef, Puppet, Salt -- to **configure that disposable environment to mirror your production environment**. Vagrant doesn't really do configuration on its own (unless you count running shell commands). #### Transferring files Copy files to/from the server using `scp` (GUI options exist and one is built-in to Ubuntu). E.g. to copy a file from the server to your local machine: `scp -i identity_file.pem ubuntu@ec2-01-234-56-789.compute-1.amazonaws.com:~/foo/bar.txt .` Or to copy from local machine to AWS instance (and place it in $HOME): `scp -i identity_file.pem file1 file2 ubuntu@ec2-01-234-56-789.compute-1.amazonaws.com:~/` If you set up your SSH config file (see above), then scp becomes a lot simpler to use: `scp foo.txt aws:~/bar.txt` #### (Re)claim ownership of directories Some commands, like `npm`, require superuser permissions. Instead of using `sudo` every time, you can claim ownership of the appropriate directory. E.g. `sudo chown -R ``whoami`` ~/.npm`