通过函数计算的Custom Runtime,您可以使用PowerShell 7.1在函数计算平台编写函数。本文介绍快速部署和调用PowerShell函数的详细步骤。您可以按需修改Powershell示例中的代码实现二次开发。
操作步骤
- 执行以下命令,初始化项目。
s init fc-custom-powershell-event -d fc-custom-powershell-event
说明 -d
用于指定该示例项目文件夹的名称,支持自定义。
- 执行以下命令,进入项目目录。
cd fc-custom-powershell-event
- 可选:按需修改函数的示例代码,实现二次开发。
- 执行以下命令,部署项目。
s deploy -y
输出示例:
Checking Service, Function (1.14s)
Creating Service, Function (0.54s)
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: powershellEventFunc
runtime: custom
handler: index.handler
memorySize: 512
timeout: 3
- 执行以下命令,远程调用函数。
s invoke -e "hello"
输出示例:
========= FC invoke Logs begin =========
FC Invoke Start RequestId: b3f20880-0dc1-4173-a190-04489b9c****
hello
FC Invoke End RequestId: b3f20880-0dc1-4173-a190-04489b9c****
Duration: 51.31 ms, Billed Duration: 52 ms, Memory Size: 512 MB, Max Memory Used: 102.37 MB
========= FC invoke Logs end =========
FC Invoke Result:
hello
End of method: invoke