Custom Runtime provided by Function Compute allows you to use the Lua language to write functions on the Function Compute platform. This topic describes how to quickly deploy and call a Lua function.
Step 1: Prepare the environment
An easy and simple way to install Funcraft is to download the executable binary files.
- Install Funcraft on the local machine. For more information, see installation instructions.
fun --versionto check whether the installation is successful.
fun configto configure Funcraft. Then configure Account ID, Access Key ID, Access Key Secret, and Default region name as prompted.
$ fun config Aliyun Account ID 1234xxx Aliyun Access Key ID xxxx Aliyun Access Key Secret xxxx Default region name cn-xxxx The timeout in seconds for each SDK client invoking 300 The maximum number of retries for each SDK client 5 Allow to anonynously report usage statistics to improve the tool over time? (Y/n)
Step 2: Deploy and call a function
- Run the following command to clone the sample project to your local machine.
git clone https:// github.com/awesome-fc/fc-custom-demoNote If you do not have git installed, enter https://github.com/awesome-fc/fc-custom-demo in the address bar of your browser. Click the download button to download directly.
- Run the following command to access the cloned sample project:
- Run the following command to deploy the project to the Function Compute instance:
fun deploy -y ... Waiting for service lua-demo to be deployed... Waiting for function fc-lua to be deployed... Waiting for packaging function fc-lua code... The function fc-lua has been packaged. A total of 7 files were compressed and the final size was 10.62 MB function fc-lua deploy success service lua-demo deploy success
- Run the following command to call the deployed function:
fun invoke -e "Hello World" ... ========= FC invoke Logs begin ========= FC Invoke Start RequestId: dcc2ff81-2318-4a89-abae-c181ede22b79, client: 220.127.116.11, server: , request: "POST /invoke HTTP/1.1", host: "18.104.22.168:9000" 2020/05/10 13:16:21 [notice] 7#7: *2 [lua] main.lua:17: FC Invoke End RequestId: dcc2ff81-2318-4a89-abae-c181ede22b79, client: 22.214.171.124, server: , request: "POST /invoke HTTP/1.1", host: "126.96.36.199:9000" 188.8.131.52 184.108.40.206 0.000 [10/May/2020:13:16:21 +0000] "POST /invoke HTTP/1.1" 200 22 "-" "Go-http-client/1.1" "-" dcc2ff81-2318-4a89-abae-c181ede22b79 Duration: 3.42 ms, Billed Duration: 100 ms, Memory Size: 512 MB, Max Memory Used: 4.66 MB ========= FC invoke Logs end ========= FC Invoke Result: Hello World