This topic describes how to deploy a web.py application to Function Compute. Function Compute provides a method different from traditional deployment methods. You can deploy a traditional web.py application to Function Compute and use the application for production without performing operations such as purchasing a server. The deployed web.py application can use the auto scaling, pay-as-you-go, and O&M-free features of Function Compute.

Prerequisites

The following operations are complete:

Procedure

  1. Run the following command in the specified directory to initialize a project:
    s init devsapp/start-webpy -d start-webpy
    The -d parameter specifies the project name. In this example, the project name is start-webpy.
    Note Skip this step if the item exists.
    Sample command output:
     Serverless Awesome: https://github.com/Serverless-Devs/package-awesome
    
     devsapp!start-webpy@0.0.8.zip file decompression completed
     please select credential alias default
    
         _    _      _
        | |  | |    | |
        | |  | | ___| |__   _ __  _   _
        | |/\| |/ _ \ '_ \ | '_ \| | | |
        \  /\  /  __/ |_) || |_) | |_| |
         \/  \/ \___|_.__(_) .__/ \__, |
                           | |     __/ |
                           |_|    |___/
    
    
        Welcome to the start-webpy application
         This application requires to open these services:
             FC : https://fc.console.aliyun.com/
             ACR: https://cr.console.aliyun.com/
         This application can help you quickly deploy the Web.py project:
             Full yaml configuration: https://github.com/devsapp/webpy#%E5%AE%8C%E6%95%B4yaml
             Web.py development docs: http://www.webpy.org/
         This application homepage: https://github.com/devsapp/start-webpy
    
    
     Thanks for using Serverless-Devs
     You could [cd /test/start-webpy] and enjoy your serverless journey!
    ️ If you need help for this example, you can use [s -h] after you enter folder.
     Document Star: https://github.com/Serverless-Devs/Serverless-Devs
  2. Run the following command to go to the project directory:
    cd start-webpy
  3. Run the following command to deploy the project:
    s deploy
    Sample command output:
    [2021-08-31T10:23:36.328] [INFO ] [S-CLI] - Start ...
    [2021-08-31T10:23:36.338] [INFO ] [S-CLI] - Start the pre-action
    [2021-08-31T10:23:36.338] [INFO ] [S-CLI] - Action: pip3 install -t . -r requirements.txt
    WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
    Collecting web.py==0.61 (from -r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/ed/f5/2dfe7585f13e3847d6e1d895bd08f4c7fba91e46e0d2bf9e433969c6c78d/web.py-0.61-py3-none-any.whl (78 KB)
        100% |████████████████████████████████| 81 KB 14.7 MB/s
    Collecting cheroot (from web.py==0.61->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/46/95/86fe6480af78fea7b0e7e1bf02e6acd4cb9e561ea200bd6d6e1398fe5426/cheroot-8.5.2-py2.py3-none-any.whl (97 KB)
        100% |████████████████████████████████| 102 KB 44.4 MB/s
    Collecting more-itertools>=2.6 (from cheroot->web.py==0.61->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/5f/3c/e3ee43177a86b448c3fea1d090238c365ea1a80f015836a8a18fbbaccd63/more_itertools-8.8.0-py3-none-any.whl (48 KB)
        100% |████████████████████████████████| 51 KB 40.6 MB/s
    Collecting six>=1.11.0 (from cheroot->web.py==0.61->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl
    Collecting jaraco.functools (from cheroot->web.py==0.61->-r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/b5/da/e51e7b58c8fe132990edd1e3ef25bcd9801eb7f91d0f642ac7f8d97e4a36/jaraco.functools-3.3.0-py3-none-any.whl
    Installing collected packages: more-itertools, six, jaraco.functools, cheroot, web.py
    Successfully installed cheroot-8.5.2 jaraco.functools-3.3.0 more-itertools-8.8.0 six-1.16.0 web.py-0.61
    Target directory /test/start-webpy/src/__pycache__ already exists. Specify --upgrade to force replacement.
    [2021-08-31T10:23:37.594] [INFO ] [S-CLI] - End the pre-action
      devsapp!webpy@0.0.8.zip file decompression completed
     Using web framework type: nas, If you want to deploy with container, you can [s cli fc-default set web-framework container] to switch.
    (node:9695) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
    (Use `node --trace-deprecation ...` to show where the warning was created)
      End of request
      Deployed.
      End of request
    [2021-08-31T10:24:01.783] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen
    [2021-08-31T10:24:01.785] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-08-31T10:24:01.785] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-08-31T10:24:01.785] [INFO ] [FC-DEPLOY] - Using accessKeySecret: KdcUEJLoGto****
     Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch.
    [2021-08-31T10:24:02.442] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-webpy exists
    [2021-08-31T10:24:02.803] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole
    [2021-08-31T10:24:03.111] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists
    [2021-08-31T10:24:03.292] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole
    [2021-08-31T10:24:03.397] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists
    [2021-08-31T10:24:03.511] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically
    [2021-08-31T10:24:04.295] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen
    [2021-08-31T10:24:04.415] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen
    [2021-08-31T10:24:04.544] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen
    [2021-08-31T10:24:04.692] [INFO ] [FC-DEPLOY] - Generated vpcConfig:
    securityGroupId: sg-wz92ctigpi221smc****
    vSwitchId: vsw-wz9qnuult4q5g4f7n****
    vpcId: vpc-wz9x9bzs0wtvjgt6n****
    
    [2021-08-31T10:24:04.692] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically
    [2021-08-31T10:24:30.271] [INFO ] [FC-DEPLOY] - Generated nasConfig:
    groupId: 10003
    mountPoints:
      - fcDir: /mnt/auto
        nasDir: /serverless-devs-webpy
        serverAddr: example.com
    userId: 10003
    
    [2021-08-31T10:24:30.273] [INFO ] [FC-DEPLOY] - Checking Function webpy exists
    [2021-08-31T10:24:30.390] [WARN ] [FC-DEPLOY] - Image registry.cn-shenzhen.aliyuncs.com/web-framework/python3:0.0.1 dose not exist locally.
    Maybe you need to run 's build' first if it dose not exist remotely.
    [2021-08-31T10:24:30.398] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-webpy exists
    [2021-08-31T10:24:30.516] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-webpy exists
    [2021-08-31T10:24:30.647] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-webpy
    [2021-08-31T10:24:30.648] [INFO ] [FC-DEPLOY] - Creating function: webpy
    [2021-08-31T10:24:30.648] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-webpy"]
      Make service serverless-devs-webpy success.
      Make function serverless-devs-webpy/webpy success.
      Make trigger serverless-devs-webpy/webpy/serverless-devs-webpy success.
    [2021-08-31T10:24:33.633] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-webpy exists
    [2021-08-31T10:24:33.700] [INFO ] [FC-DEPLOY] - Checking Function webpy exists
    [2021-08-31T10:24:33.830] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-webpy exists
    [2021-08-31T10:24:34.037] [INFO ] [FC-DEPLOY] - Creating custom domain: webpy.serverless-devs-webpy.188077086902****.cn-shenzhen.fc.devsapp.net
    [2021-08-31T10:24:34.776] [INFO ] [FC-DOMAIN] - Creating custom domain: webpy.serverless-devs-webpy.188077086902****.cn-shenzhen.fc.devsapp.net
    
    There is auto config in the service: serverless-devs-webpy
    [2021-08-31T10:24:35.308] [INFO ] [WEB-FRAMEWORK] - nas component get src is: ./src
    Packing ...
    Package complete.
     Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-webpy/webpy/src.zip
      File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-webpy/webpy/src.zip
      upload done
    [2021-08-31T10:25:07.656] [INFO ] [FC-NAS] - unzipping file
    [2021-08-31T10:25:08.824] [INFO ] [FC-NAS] - unzip done
      Try container acceleration
    framework-test:
      region: cn-shenzhen
      serviceName: serverless-devs-webpy
      functionName: webpy
      customDomains:
        - >-
          http://webpy.serverless-devs-webpy.188077086902****.cn-shenzhen.fc.devsapp.net

Result

After the project is deployed, you can view the temporary domain name generated by Function Compute in the execution output. The temporary domain name can be used to access the newly deployed application. For example, run the following command to access the application:

curl http://webpy.serverless-devs-webpy.188077086902****.cn-shenzhen.fc.devsapp.net
Note The temporary domain name is used only for demonstration and development purposes. It is valid for a limited period of time. You must use a domain name that has obtained an Internet Content Provider (ICP) filing from Alibaba Cloud for production. For more information, see Configure a custom domain name.