This topic describes how to create a custom runtime in Python by using a Tornado application.


You have installed Tornado. For more information, see Install Tornado.


  1. Write the code. Example:
    import tornado.ioloop
    import tornado.web
    import os
    class MainHandler(tornado.web.RequestHandler):    
        def get(self):        
            self.write("GET: Hello world")     
        def post(self):        
            self.write("POST: Hello world")
    def make_app():    
        return tornado.web.Application([        
            r"/. *", MainHandler),    
    if __name__ == "__main__":    
        app = make_app()    
        port = os.environ.get("FC_SERVER_PORT", "9000")    
  2. Write a file named bootstrap to start the HTTP server for the preceding code and grant it the permission to run the code. Example:
    Notice The code must contain the #! /bin/bash comment.
    #! /bin/bash
  3. Compress the and bootstrap files into a ZIP package, and then create a function that uses the custom runtime based on this ZIP package.
    Note In this case, the handler of the function is useless. You can enter any string that meets the character set constraints of handlers in Function Compute.
    root@33a2b0c2****:/code# ls -ll 
    total 16
    -rwxr-xr-x   1 root  staff    17 Aug 16 22:19 bootstrap
    -rw-r--r--   1 root  staff   414 Aug 16 17:24
    drwxr-xr-x  38 root  staff  1216 Aug 16 22:20 tornado
    root@33a2b0c2****:/code# zip -r *
    root@33a2b0c2****:/code# ls -ll
    -rw-r--r--  1 root  staff  943389 Aug 16 22:24