You can use C++ to write functions in a custom container of Function Compute. This topic describes how to deploy and invoke a C++ function. You can also modify the C++ sample code as needed for custom development.


  1. Run the following command in the specified directory to initialize a project:
    s init start-fc-custom-container-event-cpp -d start-cc-event-cpp
    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 start-cc-event-cpp
  3. Optional: Modify the sample code as needed for custom development.
  4. Modify the s.yaml file.
    Change the value of the image field in the s.yaml file to your image name.
  5. Run the following command to deploy the project:
    s deploy -y
    Sample command output:
    [2022-02-09 06:20:43] [INFO] [S-CLI] - Start the pre-action
    [2022-02-09 06:20:43] [INFO] [S-CLI] - Action: s build --use-docker --dockerfile ./code/Dockerfile
    [2022-02-09 06:20:44] [INFO] [FC-BUILD] - Build artifact start...
    [2022-02-09 06:20:44] [INFO] [FC-BUILD] - Use docker for building.
    [2022-02-09 06:20:44] [INFO] [FC-BUILD] - Building image...
    Sending build context to Docker daemon  3.707MB
    Successfully built 6eb96a23f2a4
    Successfully tagged
    Build image( successfully
    [2022-02-09 06:21:03] [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
    [2022-02-09 06:21:03] [INFO] [S-CLI] - End the pre-action
    8f0b8fdd795f: Pushed
    nginx: digest: sha256:2f94960e325d8b3bc33226eb183bc1ad2b2bbd073c6996f9723a44d51ed1afc1 size: 1155
     Checking Service, Function (85.52s)
     Creating Service, Function (0.41s)
    There is auto config in the service: hello-world-service
    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: hello-world-service
        name:       cpp-event-function
        runtime:    custom-container
        handler:    not-used
        memorySize: 256
        timeout:    60
  6. Run the following command to remotely invoke the function:
    s invoke -e '{"key":"val"}'
    Sample command output:
    ========= FC invoke Logs begin =========
    /invoke is called.
    FC Invoke Start RequestId: c212ecbb-f5c8-4a0f-b9cf-80be2d3c4e07
    2022-02-09T06:24:06 c212ecbb-f5c8-4a0f-b9cf-80be2d3c4e07 [INFO] handling invoke
    FC Invoke End RequestId: c212ecbb-f5c8-4a0f-b9cf-80be2d3c4e07
    Duration: 1.74 ms, Billed Duration: 2 ms, Memory Size: 256 MB, Max Memory Used: 0.42 MB
    ========= FC invoke Logs end =========
    FC Invoke Result:
    End of method: invoke