You can use Python to write functions in a custom container of Function Compute. This topic describes how to deploy and invoke a Python 3.9 function. You can also
modify the Python sample code as needed for custom development.
Procedure
- Run the following command in the specified directory to initialize a project:
s init start-fc-custom-container-event-python3.9 -d start-cc-py39
Note -d
specifies the name of the folder in which the sample project resides. You can customize
the folder name as required.
- Run the following command to go to the project directory:
- Optional: Modify the sample code as needed for custom development.
- Modify the s.yaml file.
Change the value of the image
field in the s.yaml file to your image name.
- Run the following command to deploy the project:
s deploy -y
Sample command output:
[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
- Run the following command to remotely invoke the function:
s invoke -e "hello world"
Sample command output:
========= 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