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 as needed for custom development.


The following operations are complete:


  1. Run the following command to initialize a project:
    s init fc-custom-ruby-event -d fc-custom-ruby-event
    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-ruby-event
  3. Optional: Modify the sample code as needed for custom development.
  4. Run the following command to install dependencies:
    s deploy -y
    Sample command output:
     Checking Service, Function (0.64s)
     Creating Service, Function (0.41s)
    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:       rubyEventFunc
        runtime:    custom
        handler:    index.handler
        memorySize: 512
        timeout:    3
  5. Run the following command to remotely invoke the function:
    s invoke -e "hello"
    Sample command output:
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: 354b196f-ece5-453f-861f-f9848fe2****
    FC Invoke End RequestId: 354b196f-ece5-453f-861f-f9848fe2****
    Duration: 1.81 ms, Billed Duration: 2 ms, Memory Size: 512 MB, Max Memory Used: 16.82 MB
    ========= FC invoke Logs end =========
    FC Invoke Result:
    End of method: invoke