This topic describes how to deploy a Bottle application to Function Compute. Function Compute provides a method different from traditional deployment methods. You can deploy a traditional Bottle application to Function Compute and use the application for production without performing operations such as purchasing a server. The deployed Bottle 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-bottle -d start-bottle
    The -d parameter specifies the project name. In this example, the project name is start-bottle.
    Note Skip this step if the item exists.
    Sample command output:
     Serverless Awesome: https://github.com/Serverless-Devs/package-awesome
    
     devsapp!start-bottle@0.0.11.zip file decompression completed
     please select credential alias default
    
         ______            _     _   __
        |_   _ \          / |_  / |_[  |
          | |_) |   .--. `| |-'`| |-'| | .---.
          |  __'. / .'`\ \| |   | |  | |/ /__\\
         _| |__) || \__. || |,  | |, | || \__.,
        |_______/  '.__.' \__/  \__/[___]'.__.'
    
    
        Welcome to the start-bottle 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 Bottle project:
             Full yaml configuration: https://github.com/devsapp/bottle#%E5%AE%8C%E6%95%B4yaml
             Bottle development docs: http://www.bottlepy.com/docs/dev/
         This application homepage: https://github.com/devsapp/start-bottle
    
    
     Thanks for using Serverless-Devs
     You could [cd /test/start-bottle] 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-bottle
  3. Run the following command to deploy the project:
    s deploy
    Sample command output:
    [2021-08-30T17:57:12.992] [INFO ] [S-CLI] - Start ...
    [2021-08-30T17:57:13.001] [INFO ] [S-CLI] - Start the pre-action
    [2021-08-30T17:57:13.001] [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 bottle==0.12.18 (from -r requirements.txt (line 1))
      Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/e9/39/2bf3a1fd963e749cdbe5036a184eda8c37d8af25d1297d94b8b7aeec17c4/bottle-0.12.18-py3-none-any.whl (89 KB)
        100% |████████████████████████████████| 92 KB 3.2 MB/s
    Installing collected packages: bottle
    Successfully installed bottle-0.12.18
    [2021-08-30T17:57:13.691] [INFO ] [S-CLI] - End the pre-action
      devsapp!bottle@0.0.6.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:14604) [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-30T17:57:35.130] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen
    [2021-08-30T17:57:35.131] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-08-30T17:57:35.131] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-08-30T17:57:35.132] [INFO ] [FC-DEPLOY] - Using accessKeySecret: ldHUiJLoGto****
      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-30T17:57:35.808] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-bottle exists
    [2021-08-30T17:57:36.056] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole
    [2021-08-30T17:57:36.420] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists
    [2021-08-30T17:57:36.604] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole
    [2021-08-30T17:57:36.699] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists
    [2021-08-30T17:57:36.820] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically
    [2021-08-30T17:57:37.625] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen
    [2021-08-30T17:57:37.732] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen
    [2021-08-30T17:57:37.941] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen
    [2021-08-30T17:57:38.117] [INFO ] [FC-DEPLOY] - Generated vpcConfig:
    securityGroupId: sg-wz92ctigpi221smc****
    vSwitchId: vsw-wz9qnuult4q5g4f7n****
    vpcId: vpc-wz9x9bzs0wtvjgt6n****
    
    [2021-08-30T17:57:38.118] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically
    [2021-08-30T17:58:02.873] [INFO ] [FC-DEPLOY] - Generated nasConfig:
    groupId: 10003
    mountPoints:
      - fcDir: /mnt/auto
        nasDir: /serverless-devs-bottle
        serverAddr: example.com
    userId: 10003
    
    [2021-08-30T17:58:02.875] [INFO ] [FC-DEPLOY] - Checking Function bottle exists
    [2021-08-30T17:58:03.004] [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-30T17:58:03.019] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-bottle exists
    [2021-08-30T17:58:03.310] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-bottle exists
    [2021-08-30T17:58:03.460] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-bottle
    [2021-08-30T17:58:03.460] [INFO ] [FC-DEPLOY] - Creating function: bottle
    [2021-08-30T17:58:03.460] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-bottle"]
      Make service serverless-devs-bottle success.
      Make function serverless-devs-bottle/bottle success.
      Make trigger serverless-devs-bottle/bottle/serverless-devs-bottle success.
    [2021-08-30T17:58:06.628] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-bottle exists
    [2021-08-30T17:58:06.706] [INFO ] [FC-DEPLOY] - Checking Function bottle exists
    [2021-08-30T17:58:06.849] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-bottle exists
    [2021-08-30T17:58:07.074] [INFO ] [FC-DEPLOY] - Creating custom domain: bottle.serverless-devs-bottle.188077086902****.cn-shenzhen.fc.devsapp.net
    [2021-08-30T17:58:07.847] [INFO ] [FC-DOMAIN] - Creating custom domain: bottle.serverless-devs-bottle.188077086902****.cn-shenzhen.fc.devsapp.net
    
    There is auto config in the service: serverless-devs-bottle
    [2021-08-30T17:58:08.170] [INFO ] [WEB-FRAMEWORK] - nas component get src is: ./src
    Packing ...
    Package complete.
      Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-bottle/bottle/src.zip
      File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-bottle/bottle/src.zip
      upload done
    [2021-08-30T17:58:39.140] [INFO ] [FC-NAS] - unzipping file
    [2021-08-30T17:58:39.274] [INFO ] [FC-NAS] - unzip done
      Try container acceleration
    framework-test:
      region: cn-shenzhen
      serviceName: serverless-devs-bottle
      functionName: bottle
      customDomains:
        - >-
          http://bottle.serverless-devs-bottle.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://bottle.serverless-devs-bottle.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.