This time, we will build a Python development server on Amazon Web Service (AWS). Anaconda is used to build the Python environment, and Jupyter Notebook is used as the IDE.
The author's environment is as follows.
item | Contents |
---|---|
Machine | MacBook Air 13-inch, Early 2015 |
OS | OS X Yosemite 10.10.5 |
Mem | 8 GB |
This time, create an EC2 instance with the following configuration.
item | Contents |
---|---|
Region | Oregon |
Instance type | t2.small |
EBS | General purpose SSD 30 GB |
Security group | Inbound = TCP:22 & 8888, Outbount = all, Anywhere |
Describe the following settings in ~ / .ssh / config
(create a new one if there is no ~ / .ssh / config
). XXXXX.pem
is a private key file issued by AWS.
~/.ssh/config
Host (Describe any host name: ex. pydev)
hostname ec2-XXX-XXX-XXX-XXX.us-west-2.compute.amazonaws.com
identityfile ~/.ssh/XXXXX.pem
user ec2-user
Log in to the server.
$ ssh pydev
Install Git, tmux, Emacs, etc.
$ sudo yum -y install git tmux emacs gcc gcc-c++ python-setuptools python-devel postgresql-devel
After that, work on tmux.
$ tmux
Execute the following command.
$ wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda3-4.0.0-Linux-x86_64.sh
$ bash Anaconda3-4.0.0-Linux-x86_64.sh
$ source .bashrc
Execute the following command
$ jupyter notebook --generate-config
$ source activate root
$ ipython
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password: XXXXXX
Verify password: XXXXXX
Out[2]: 'sha1:XXXXXXXXXXXXXXXXXXXXXXXXXXXX'
Make a note of the output'sha1: XXXXXXXXXXXXXXXXXXXXXXXXXXXX'.
Describe the following settings in ~ / .jupyter / jupyter_notebook_config.py
.
``~/.jupyter/jupyter_notebook_config.py ... c.NotebookApp.ip = '*' ... c.NotebookApp.open_browser = False ... c.NotebookApp.password = 'sha1:XXXXXXXXXXXXXXXXXXXXXXXXXXXX'
Start the Jupyter Notebook server with the following command.
$ jupyter notebook &
`/etc/rc.local`To`nohup jupyter notebook &`If you add, the Jupyter Notebook server will start automatically when the instance is restarted.
#Log in to Jupyter Notebook from your browser
From your local browser`http://[Server hostname or IP]:8888/`When you access, the login screen is displayed. You can log in by entering the password entered in the Jupyter Notebook environment settings.
#in conclusion
At this point, you have built a Python development environment on AWS EC2. With the current settings, the IP of the server will change when you restart, so it is better to fix it using Elasatic IP. If the machine power is insufficient, you can increase the instance type as appropriate.
#References
* [Amazon Web Service (AWS)](https://aws.amazon.com/jp/)
* [Anaconda](https://www.continuum.io/why-anaconda)
* [Jupyter Project](http://jupyter.org)
Recommended Posts