I easily built an operating environment for Python3 + Tornado on AWS EC2.

Overview

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.

Target

The goal is to access EC2 from a browser and see "Hello, world".

Construction contents

  1. Amazon Linux
  2. Python 3.5.2
  3. Tornado 4.4

Python3 installation procedure

01. Install the required dependencies.

$ 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

02. Install Pyenv.

$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv

03. Pass the path of 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

04. Install Python.

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

Tornado installation procedure

01. Update pip to the latest version.

$ pip install --upgrade pip

02. Install Tornado.

$ pip install tornado

Hello world program preparation

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()

Operation check

01. Execute the Hello world program.

# python helloworld.py

02. Access from a browser with the specified URL of Port.

e.g.) http://ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com:8888

helloworld.png

At the end

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.

Recommended Posts

I easily built an operating environment for Python3 + Tornado on AWS EC2.
Building an environment to execute python programs on AWS EC2
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build an environment for machine learning using Python on MacOSX
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Create an AWS Cloud9 development environment on your Amazon EC2 instance
Build an environment for Blender built-in Python
Create an OpenCV3 + python3 environment on OSX
I built a TensorFlow environment on windows10
Building an environment for "Tello_Video" on Raspbian
Building an environment for "Tello_Video" on Windows
[Definitive Edition] Building an environment for learning "machine learning" using Python on Windows
[Definitive Edition] Building an environment for learning "machine learning" using Python on Mac
Prepare the development environment for Python on AWS Cloud9 (pip install & time change)
[2020 version] How to install Python3 on AWS EC2
Build python environment with pyenv on EC2 (ubuntu)
Building an environment for executing Python scripts (for mac)
How to build an environment for using multiple versions of Python on Mac
Building an Anaconda environment for Python with pyenv
Python development on Ubuntu on AWS EC2 (using JupyterLab)
Building an environment for matplotlib + cartopy on Mac
Set up python Tornado environment on raspbian jessie
Create a Python execution environment on IBM i
Script to easily create a client device environment for AWS IoT (Python v2 version)
I tried to build an environment for machine learning with Python (Mac OS X)
Build an interactive environment for machine learning in Python
I tried Python on Mac for the first time.
Deployment procedure on AWS (2) Server (EC2 instance) environment settings
Building an environment for "Tello_Video" on Mac OS X
I tried python on heroku for the first time
I made a Python3 environment on Ubuntu with direnv.
Building an environment for natural language processing with Python
Create an environment for MkDocs on Amazon Linux (attempted)
Execute python3 system with PHP exec () on AWS EC2
Support for Python 2.7 runtime on AWS Lambda (as of 2020.1)
Procedure for building a CDK environment on Windows (Python)
I want to AWS Lambda with Python on Mac!
Use AWS SDK for Python (boto) under Proxy environment
Python environment for projects
I built an environment for machine learning from scratch (windows10 + Anaconda + VSCode + Tensorflow + GPU version)
I created an environment for Masonite, a Python web framework similar to Laravel, with Docker!
Posted as an attachment to Slack on AWS Lambda (Python)
[AWS] I tried using EC2, RDS, Django. Environment construction from 1
Run AWS IoT Device SDK for Python on Raspberry Pi
Let's get started with Python ~ Building an environment on Windows 10 ~
Build an Ubuntu python development environment on Google Cloud Platform
Install AWS SDK for PHP on AWS EC2 (PHP7.2 + Apache2.4.41 + OPCashe + Composer)
I just built a virtual environment with AWS lambda layer
Easily build network infrastructure and EC2 with AWS CDK Python
Create a virtual environment for python on mac [Very easy]
Build a python environment on CentOS 7.7 for your home server
How to easily create an environment where python code runs on Jupyter without polluting the local environment
Anyone can understand how to build an initial environment for Python on Mac September 2016 (pyenv + virutalenv)
Python environment construction For Mac
Build Python environment on Windows
Python3 environment construction (for beginners)
Build python environment on windows
Python --Install MySQLDB on EC2
[For organizing] Python development environment
I ran python on windows