I was able to build a development environment locally by referring to the article "Getting started with Python! ~ ① Environment construction ~", so now it's time to start operation. Toward, I tried to create the operating environment of Python3 + Tornado on EC2 with the minimum procedure.
Estimated working time: 10 minutes
In production operation, we plan to use React on the Futonro end and Tornado on the back end.
The goal is to access EC2 from a browser and see "Hello, world".
$ yum groupinstall "Development Tools"
$ yum install mlocate
$ yum install openssl-devel
$ yum install bzip2-devel
$ yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite3 sqlite-devel openssl-devel
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ vim ~/.bashrc
-----
# Add Pyenv Path
export PYENV_ROOT="${HOME}/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
fi
Immediately reflect the settings.
$ source ~/.bashrc #.bashrc
Check the Python version.
$ pyenv install --list
Install Python3.
$ pyenv install 3.5.2
Switch from Python version 2.7.12 to 3.5.2.
$ python -V
Python 2.7.12
$ pyenv global 3.5.2
$ python -V
Python 3.5.2
$ pip install --upgrade pip
$ pip install tornado
This time, place the program directly under / home / ec2-user / helloworld /.
helloword.py
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
# python helloworld.py
e.g.) http://ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com:8888
It was easier than I expected to build an environment, so if you feel a threshold in building an environment, please refer to this article and take on the challenge. Originally it was PHPer, but since I started working on Python, I would like to summarize the researched contents in an article. In the future, I plan to create an article with the contents of the research to build a RESTful API server using Tornado.