通过函数计算的Custom Runtime,您可以使用Ruby 2.7在函数计算平台编写函数。本文介绍如何快速部署和调用Ruby函数。您可以修改Ruby示例中的代码实现二次开发,满足您的需求。

前提条件

您已完成以下操作:

操作步骤

  1. 在目标目录中,执行以下命令,初始化项目。
    s init start-fc-custom-samples -d start-fc-custom-samples
  2. 执行以下命令,进入项目目录。
    cd start-fc-custom-samples/ruby/event-demo/
  3. 执行以下命令,安装依赖。
    s deploy
    输出示例:
    [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
    
    fc-ruby-demo-fc-ruby:
      region: cn-hangzhou
      service:
        name: custom-demo
      function:
        name: rubyEventFunc
        runtime: custom
        handler: index.handler
        memorySize: 512
        timeout: 3
  4. 执行以下命令,远程调用函数。
    s invoke -e "{}"
    输出示例:
    [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