You can use the Custom Runtime of Function Compute to write Ruby functions in Function Compute. This topic describes how to deploy and invoke a Ruby function. You can modify the sample Ruby code.

Prerequisites

Before you begin, make sure that you have completed the following operations:
  • Install Node.js 8.6.0 or later. For more information, visit Downloads.

Procedure

  1. Run the following command to clone the sample project to the on-premises machine:
    git clone https://github.com/awesome-fc/fc-custom-demo          
    Note If you do not install Git, you can download the sample project from https://github.com/awesome-fc/fc-custom-demo.
  2. Optional:Modify the sample code in the ruby-demo directory to implement your business logic.
  3. Run the following command to go to the cloned sample project:
    1. Run the following command to go to the ruby-demo directory:
      cd ruby-demo 
  4. Run the following command to deploy the project to Function Compute:
    fun deploy -y     
    The following output is returned:
    ...
    Waiting for service ruby-demo to be deployed...
            Waiting for function fc-ruby to be deployed...
                    Waiting for packaging function fc-ruby code...
                    The function fc-ruby has been packaged. A total of 4 files were compressed and the final size was 1.45 KB
            function fc-ruby deploy success
    service ruby-demo deploy success
  5. Run the following command to invoke the deployed function:
    fun invoke -e "Hello World"   
    The following output is returned:
    ...
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: a9c4dc8a-4b5b-48e0-9a3f-70310531ae61
    Hello World
    FC Invoke End RequestId: a9c4dc8a-4b5b-48e0-9a3f-70310531ae61
    
    Duration: 0.69 ms, Billed Duration: 100 ms, Memory Size: 512 MB, Max Memory Used: 5.06 MB
    ========= FC invoke Logs end =========
    
    FC Invoke Result:
    Hello World