You can use the custom runtime of Function Compute to write functions in Function Compute by using Ruby 2.7. This topic describes how to deploy and invoke a Ruby function. You can modify the Ruby 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/ruby/event-demo/
  3. Run the following command to install dependencies:
    s deploy
    Sample output:
    [2021-09-08T15:23:15.388] [INFO ] [S-CLI] - Start ...
    [2021-09-08T15:23:15.941] [INFO ] [FC-DEPLOY] - Using region: cn-hangzhou
    [2021-09-08T15:23:15.942] [INFO ] [FC-DEPLOY] - Using access alias: default
    [2021-09-08T15:23:15.942] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
    [2021-09-08T15:23:15.942] [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-08T15:23:16.159] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-08T15:23:16.352] [INFO ] [FC-DEPLOY] - Checking Function rubyEventFunc exists
      Make service custom-demo success.
      Make function custom-demo/rubyEventFunc success.
    [2021-09-08T15:23:17.100] [INFO ] [FC-DEPLOY] - Checking Service custom-demo exists
    [2021-09-08T15:23:17.197] [INFO ] [FC-DEPLOY] - Checking Function rubyEventFunc exists
    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: rubyEventFunc
        runtime: custom
        handler: index.handler
        memorySize: 512
        timeout: 3
  4. Run the following command to invoke the function:
    s invoke -e "{}"
    Sample output:
    [2021-09-08T15:24:43.530] [INFO ] [S-CLI] - Start ...
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: 76b7c995-f8d3-411e-8da0-c674facb3a20
    FC Invoke End RequestId: 76b7c995-f8d3-411e-8da0-c674facb3a20
    Duration: 3.75 ms, Billed Duration: 4 ms, Memory Size: 512 MB, Max Memory Used: 18.71 MB
    ========= FC invoke Logs end =========
    FC Invoke Result:
    End of method: invoke