通过函数计算的Custom Runtime,您可以使用Ruby 2.7在函数计算平台编写函数。本文介绍如何快速部署和调用Ruby函数。您可以按需修改Ruby示例中的代码实现二次开发。
操作步骤
- 执行以下命令,初始化项目。
s init fc-custom-ruby-event -d fc-custom-ruby-event
说明 -d
用于指定该示例项目文件夹的名称,支持自定义。
- 执行以下命令,进入项目目录。
- 可选:按需修改函数的示例代码,实现二次开发。
- 执行以下命令,安装依赖。
s deploy -y
输出示例:
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
helloworld:
region: cn-hangzhou
service:
name: hello-world-service
function:
name: rubyEventFunc
runtime: custom
handler: index.handler
memorySize: 512
timeout: 3
- 执行以下命令,远程调用函数。
s invoke -e "hello"
输出示例:
========= FC invoke Logs begin =========
FC Invoke Start RequestId: 354b196f-ece5-453f-861f-f9848fe2****
hello
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:
hello
End of method: invoke