You can use the custom runtime of Function Compute to write Lua functions in Function Compute. This topic describes how to deploy and invoke a Lua function. You can modify the
Lua sample code as needed for custom development.
Procedure
- Run the following command to initialize a project:
s init fc-custom-lua-event -d fc-custom-lua-event
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.
- Run the following command to deploy the project:
s deploy -y
Sample command output:
[2022-01-26 08:57:00] [INFO] [S-CLI] - Start the pre-action
[2022-01-26 08:57:00] [INFO] [S-CLI] - Action: s build --use-docker
[2022-01-26 08:57:01] [INFO] [FC-BUILD] - Build artifact start...
[2022-01-26 08:57:02] [INFO] [FC-BUILD] - Use docker for building.
[2022-01-26 08:57:02] [INFO] [FC-BUILD] - No need build for this project.
[2022-01-26 08:57:02] [INFO] [FC-BUILD] - Build artifact successfully.
Tips for next step
======================
* Invoke Event Function: s local invoke
* Invoke Http Function: s local start
* Deploy Resources: s deploy
End of method: build
[2022-01-26 08:57:02] [INFO] [S-CLI] - End the pre-action
Checking Service, Function (3.57s)
Creating Service, Function (114.37s)
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: luaEventFunc
runtime: custom
handler: index.handler
memorySize: 1024
timeout: 30
- Run the following command to remotely invoke the function:
s invoke -e "hello"
Sample command output:
========= FC invoke Logs begin =========
FC Invoke Start RequestId: cbc4a3c1-72bb-4d0d-91f8-061c99a5****, client: 21.0.XX.XX, server: , request: "POST /invoke HTTP/1.1", host: "21.0.XX.XX:9000"
2022/01/26 09:04:37 [notice] 8#8: *2 [lua] main.lua:26: hello, client: 21.0.XX.XX, server: , request: "POST /invoke HTTP/1.1", host: "21.0.XX.XX:9000"
2022/01/26 09:04:37 [notice] 8#8: *2 [lua] main.lua:28: FC Invoke End RequestId: cbc4a3c1-72bb-4d0d-91f8-061c99a5****, client: 21.0.3.254, server: , request: "POST /invoke HTTP/1.1", host: "21.0.XX.XX:9000"
Duration: 1.93 ms, Billed Duration: 2 ms, Memory Size: 1024 MB, Max Memory Used: 9.44 MB
========= FC invoke Logs end =========
FC Invoke Result:
hello
End of method: invoke