You can migrate web projects in Python 3.7 by using the custom runtime of Function Compute and HTTP triggers to the cloud with a few clicks. You can use a browser or an HTTP client tool such as cURL to access a function. You can modify the Python 3.7 sample code to perform secondary development.


The following operations are complete:


  1. Run the following command in the target directory to initialize the project:
    s init start-fc-custom-samples -d start-fc-custom-samples
  2. Run the following command to go to the project directory:
    cd start-fc-custom-samples/python37/http-demo
    Note The examples described in this topic support concurrent request processing on a single instance.
  3. Run the following command to install dependencies:
    s build -d
    Sample output:
    [2021-09-09T10:41:36.043] [INFO ] [S-CLI] - Start ...
    [2021-09-09T10:41:36.829] [INFO ] [FC-BUILD] - Build artifact start...
    [2021-09-09T10:41:36.848] [INFO ] [FC-BUILD] - Use docker for building.
    [2021-09-09T10:41:36.959] [INFO ] [FC-BUILD] - Build function using image:
    [2021-09-09T10:41:37.045] [INFO ] [FC-BUILD] - skip pulling image
    [2021-09-09T10:42:05.697] [INFO ] [FC-BUILD] - Build artifact successfully.
    Tips for next step
    * Invoke Event Function: s local invoke
    * Invoke Http Function: s local start
    * Deploy Resources: s deploy
    End of method: build
  4. Run the following command to deploy the project:
    s deploy -y
    Sample output:
    [2021-09-09T10:43:24.748] [INFO ] [S-CLI] - Start ...
    [2021-09-09T10:43:25.323] [INFO ] [FC-DEPLOY] - Using region: cn-hangzhou
    [2021-09-09T10:43:25.324] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-09-09T10:43:25.324] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-09-09T10:43:25.325] [INFO ] [FC-DEPLOY] - Using accessKeySecret: LTAI4G4cwJkK4Rza6xd9****
      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-09-09T10:43:25.591] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-09T10:43:25.803] [INFO ] [FC-DEPLOY] - Checking Function pyHttpFunc exists
    [2021-09-09T10:43:25.880] [INFO ] [FC-DEPLOY] - Fc detects that you have run build command for function: pyHttpFunc.
    [2021-09-09T10:43:25.880] [INFO ] [FC-DEPLOY] - Using codeUri: /test/start-fc-custom-samples/python37/http-demo/.s/build/artifacts/custom-demo/pyHttpFunc
    [2021-09-09T10:43:25.881] [INFO ] [FC-DEPLOY] - Fc add/append some content to your origin environment variables for finding dependencies generated by build command.
      "LD_LIBRARY_PATH": "/code/.s/root/usr/local/lib:/code/.s/root/usr/lib:/code/.s/root/usr/lib/x86_64-linux-gnu:/code/.s/root/usr/lib64:/code/.s/root/lib:/code/.s/root/lib/x86_64-linux-gnu:/code/.s/root/python/lib/python2.7/site-packages:/code/.s/root/python/lib/python3.6/site-packages:/code:/code/lib:/usr/local/lib",
      "PATH": "/code/.s/root/usr/local/bin:/code/.s/root/usr/local/sbin:/code/.s/root/usr/bin:/code/.s/root/usr/sbin:/code/.s/root/sbin:/code/.s/root/bin:/code:/code/node_modules/.bin:/code/.s/python/bin:/code/.s/node_modules/.bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin",
      "NODE_PATH": "/code/node_modules:/usr/local/lib/node_modules",
      "PYTHONUSERBASE": "/code/.s/python"
    [2021-09-09T10:43:27.571] [INFO ] [FC-DEPLOY] - Checking Trigger http_t exists
    [2021-09-09T10:43:27.618] [INFO ] [FC-DEPLOY] - Checking Trigger http_t exists
      Make service custom-demo success.
      Make function custom-demo/pyHttpFunc success.
      Make trigger custom-demo/pyHttpFunc/http_t success.
    [2021-09-09T10:43:45.462] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-09T10:43:45.521] [INFO ] [FC-DEPLOY] - Checking Function pyHttpFunc exists
    [2021-09-09T10:43:45.593] [INFO ] [FC-DEPLOY] - Checking Trigger http_t exists
    [2021-09-09T10:43:45.717] [INFO ] [FC-DEPLOY] - Using customDomain: auto: fc will try to generate related custom domain resources automatically
      End of request
      End of request
    [2021-09-09T10:43:50.418] [INFO ] [FC-DEPLOY] - Generated auto custom domain: pyhttpfunc.custom-demo.188077086902****
    [2021-09-09T10:43:50.418] [INFO ] [FC-DEPLOY] - Creating custom domain: pyhttpfunc.custom-demo.188077086902****
    [2021-09-09T10:43:50.581] [INFO ] [FC-DOMAIN] - Creating custom domain: pyhttpfunc.custom-demo.188077086902****
    Tips for next step
    * Display information of the deployed resource: s info
    * Display metrics: s metrics
    * Display logs: s logs
    * Invoke remote function: s invoke
    * Remove Service: s remove service
    * Remove Function: s remove function
    * Remove Trigger: s remove trigger
    * Remove CustomDomain: s remove domain
      region: cn-hangzhou
        name: custom-demo
        name: pyHttpFunc
        runtime: custom
        handler: index.handler
        memorySize: 1536
        timeout: 30
        system_url: >-
          - domain: >-
        - type: http
          name: http_t


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://pyhttpfunc.custom-demo.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 Bind a custom domain name.