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


The following operations are complete:


  1. Run the following command in the specified directory to initialize a project:
    s init devsapp/start-flask -d start-flask
    The -d parameter specifies the project name. In this example, the project name is start-flask.
    Note Skip this step if the item exists.
    Sample command output:
     Serverless Awesome:
     devsapp! file decompression completed
     please select credential alias default
        ______ _           _
        |  ___| |         | |
        | |_  | | __ _ ___| | __
        |  _| | |/ _` / __| |/ /
        | |   | | (_| \__ \   <
        \_|   |_|\__,_|___/_|\_\
        Welcome to the start-flask application
         This application requires to open these services:
             FC :
         This application can help you quickly deploy the Flask project:
             Full yaml configuration:
             Flask development docs :
         This application homepage:
     Thanks for using Serverless-Devs
     You could [cd /test/start-flask] and enjoy your serverless journey!
     If you need help for this example, you can use [s -h] after you enter folder.
     Document Star:
  2. Run the following command to go to the project directory:
    cd start-flask
  3. Run the following command to deploy the project:
    s deploy
    Sample command output:
    [2021-08-30T17:20:12.059] [INFO ] [S-CLI] - Start ...
    [2021-08-30T17:20:12.070] [INFO ] [S-CLI] - Start the pre-action
    [2021-08-30T17:20:12.070] [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 Flask==1.1.2 (from -r requirements.txt (line 1))
      Downloading (94 KB)
        100% |████████████████████████████████| 102 KB 12.3 MB/s
    Collecting dataclasses==0.6 (from -r requirements.txt (line 2))
    Collecting itsdangerous>=0.24 (from Flask==1.1.2->-r requirements.txt (line 1))
    Collecting Jinja2>=2.10.1 (from Flask==1.1.2->-r requirements.txt (line 1))
      Downloading (133 KB)
        100% |████████████████████████████████| 143 KB 11.7 MB/s
    Collecting Werkzeug>=0.15 (from Flask==1.1.2->-r requirements.txt (line 1))
      Downloading (288 KB)
        100% |████████████████████████████████| 296 KB 16.6 MB/s
    Collecting click>=5.1 (from Flask==1.1.2->-r requirements.txt (line 1))
      Downloading (97 KB)
        100% |████████████████████████████████| 102 KB 34.5 MB/s
    Collecting MarkupSafe>=2.0 (from Jinja2>=2.10.1->Flask==1.1.2->-r requirements.txt (line 1))
    Collecting importlib-metadata; python_version < "3.8" (from click>=5.1->Flask==1.1.2->-r requirements.txt (line 1))
    Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->click>=5.1->Flask==1.1.2->-r requirements.txt (line 1))
    Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version < "3.8"->click>=5.1->Flask==1.1.2->-r requirements.txt (line 1))
    Installing collected packages: itsdangerous, MarkupSafe, Jinja2, dataclasses, Werkzeug, zipp, typing-extensions, importlib-metadata, click, Flask
    Successfully installed Flask-1.1.2 Jinja2-3.0.1 MarkupSafe-2.0.1 Werkzeug-2.0.1 click-8.0.1 dataclasses-0.6 importlib-metadata-4.8.0 itsdangerous-2.0.1 typing-extensions- zipp-3.5.0
    [2021-08-30T17:20:14.760] [INFO ] [S-CLI] - End the pre-action
      devsapp! 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:12474) [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
      End of request
    [2021-08-30T17:20:37.829] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen
    [2021-08-30T17:20:37.831] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-08-30T17:20:37.831] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-08-30T17:20:37.831] [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:20:38.461] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-flask exists
    [2021-08-30T17:20:38.715] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole
    [2021-08-30T17:20:39.138] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists
    [2021-08-30T17:20:39.306] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole
    [2021-08-30T17:20:39.398] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists
    [2021-08-30T17:20:39.530] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically
    [2021-08-30T17:20:40.327] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen
    [2021-08-30T17:20:40.448] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen
    [2021-08-30T17:20:40.572] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen
    [2021-08-30T17:20:40.768] [INFO ] [FC-DEPLOY] - Generated vpcConfig:
    securityGroupId: sg-wz92ctigpi221smc****
    vSwitchId: vsw-wz9qnuult4q5g4f7n****
    vpcId: vpc-wz9x9bzs0wtvjgt6n****
    [2021-08-30T17:20:40.769] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically
    [2021-08-30T17:21:06.776] [INFO ] [FC-DEPLOY] - Generated nasConfig:
    groupId: 10003
      - fcDir: /mnt/auto
        nasDir: /serverless-devs-flask
    userId: 10003
    [2021-08-30T17:21:06.778] [INFO ] [FC-DEPLOY] - Checking Function flask exists
    [2021-08-30T17:21:06.903] [WARN ] [FC-DEPLOY] - Image dose not exist locally.
    Maybe you need to run 's build' first if it dose not exist remotely.
    [2021-08-30T17:21:06.907] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-flask exists
    [2021-08-30T17:21:06.992] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-flask exists
    [2021-08-30T17:21:07.099] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-flask
    [2021-08-30T17:21:07.100] [INFO ] [FC-DEPLOY] - Creating function: flask
    [2021-08-30T17:21:07.100] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-flask"]
      Make service serverless-devs-flask success.
      Make function serverless-devs-flask/flask success.
      Make trigger serverless-devs-flask/flask/serverless-devs-flask success.
    [2021-08-30T17:21:09.939] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-flask exists
    [2021-08-30T17:21:10.009] [INFO ] [FC-DEPLOY] - Checking Function flask exists
    [2021-08-30T17:21:10.129] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-flask exists
    [2021-08-30T17:21:10.295] [INFO ] [FC-DEPLOY] - Creating custom domain: flask.serverless-devs-flask.188077086902****
    [2021-08-30T17:21:11.136] [INFO ] [FC-DOMAIN] - Creating custom domain: flask.serverless-devs-flask.188077086902****
    There is auto config in the service: serverless-devs-flask
    [2021-08-30T17:21:11.714] [INFO ] [WEB-FRAMEWORK] - nas component get src is: ./src
    Packing ...
    Package complete.
     Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-flask/flask/
      File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-flask/flask/
      upload done
    [2021-08-30T17:21:48.265] [INFO ] [FC-NAS] - unzipping file
    [2021-08-30T17:21:50.474] [INFO ] [FC-NAS] - unzip done
      Try container acceleration
      region: cn-shenzhen
      serviceName: serverless-devs-flask
      functionName: flask
        - >-


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://flask.serverless-devs-flask.188077086902****
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.