You can migrate web projects in C++ by using the custom runtime and HTTP triggers of Function Compute. You can access a function by using a browser or HTTP client tools such as cURL. You can modify the C++ sample code as needed for custom development.

Procedure

  1. Run the following command to initialize a project:
    s init fc-custom-cpp-http -d fc-custom-cpp-http
    Note -d specifies the name of the folder in which the sample project resides. You can customize the folder name as required.
  2. Run the following command to go to the project directory:
    cd fc-custom-cpp-http
  3. Optional: Modify the HttpHandler::OnInvoke and HttpHandler::OnInitialize parameters in the /sample/src/handlers/http_handler.cpp sample file for custom development.
  4. Run the following command to deploy the project:
    s deploy -y
    Sample command output:
    [2022-01-27 06:52:54] [INFO] [S-CLI] - Start the pre-action
    [2022-01-27 06:52:54] [INFO] [S-CLI] - Action: make build
    docker build -t fc-cpp-runtime  -f build-image/Dockerfile build-image
    Sending build context to Docker daemon  2.048kB
    Step 1/3 : FROM aliyunfc/runtime-custom:base
    ......
    [2022-01-27 06:54:51] [INFO] [S-CLI] - End the pre-action
     Checking Service, Function, Triggers (1.8s)
     Creating Service, Function, Triggers (4.5s)
     Generated custom domain (1.36s)
     Creating custom domain (2.6s)
    
    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
    
    
    
    helloworld:
      region:   cn-hangzhou
      service:
        name: hello-world-service
      function:
        name:       cppHttpFunc
        runtime:    custom
        handler:    index.handler
        memorySize: 512
        timeout:    3
      url:
        system_url:    https://188077086902****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/hello-world-service/cppHttpFunc/
        custom_domain:
          -
            domain: http://cpphttpfunc.hello-world-service.188077086902****.cn-hangzhou.fc.devsapp.net
      triggers:
        -
          type: http
          name: http_t

Result

After the project is deployed, you can view the temporary domain name that is generated by Function Compute in the 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://cpphttpfunc.hello-world-service.188077086902****.cn-hangzhou.fc.devsapp.net
Note You can use the temporary domain name only for demonstration and development purposes. It is valid for a limited period of time. In a production environment, you must use a domain name for which an Internet Content Provider (ICP) filing is obtained from Alibaba Cloud. For more information, see Configure a custom domain name.