通过函数计算的Custom Container,您可以使用Python在函数计算平台编写函数。本文介绍如何快速部署和调用Python 3.9函数。您可以按需修改Python的示例代码实现二次开发。
操作步骤
- 在目标目录中,执行以下命令,初始化项目。
s init start-fc-custom-container-event-python3.9 -d start-cc-py39
说明 -d
用于指定该示例项目文件夹的名称,支持自定义。
- 执行以下命令进入项目目录。
- 可选:按需修改函数的示例代码,实现二次开发。
- 修改s.yaml文件。
将s.yaml文件内的image
字段的参数值修改为您的镜像名称。
- 执行以下命令,部署项目。
s deploy -y
输出示例:
[2022-02-09 06:46:07] [INFO] [S-CLI] - Start the pre-action
......
helloworld:
region: cn-hangzhou
service:
name: hello-world-service
function:
name: py39-event-function
runtime: custom-container
handler: not-used
memorySize: 256
timeout: 60
- 执行以下命令,远程调用函数。
s invoke -e "hello world"
输出示例:
========= FC invoke Logs begin =========
FC Invoke Start RequestId: 8bb53c93-09f9-4a3d-a61f-3a2f2e0030e0
hello world
FC Invoke End RequestId: 8bb53c93-09f9-4a3d-a61f-3a2f2e0030e0
Duration: 2.46 ms, Billed Duration: 3 ms, Memory Size: 256 MB, Max Memory Used: 18.18 MB
========= FC invoke Logs end =========
FC Invoke Result:
Hello from FC event function, your input: hello world, request_id: 8bb53c93-09f9-4a3d-a61f-3a2f2e0030e0
End of method: invoke