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 sample Lua code.

Prerequisites

Before you begin, make sure that you have completed the following operations:
  • Install Node.js 8.6.0 or later. For more information, visit Downloads.

Procedure

  1. Run the following command to clone the sample project to the on-premises machine:
    git clone https://github.com/awesome-fc/fc-custom-demo          
    Note If you do not install Git, you can download the sample project from https://github.com/awesome-fc/fc-custom-demo.
  2. (Optional) Modify the sample code in the lua-demo directory to implement your business logic.
  3. Run the following command to go to the cloned sample project:
    1. Run the following command to go to the lua-demo directory:
      cd lua-demo
  4. Run the following command to deploy the project to Function Compute:
    fun deploy -y
    The following output is returned:
    ...
    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
  5. Run the following command to invoke the deployed function:
    fun invoke -e "Hello World"
    The following output is returned:
    ...
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: dcc2ff81-2318-4a89-abae-c181ede22b79, client: 21.0.3.254, server: , request: "POST /invoke HTTP/1.1", host: "21.0.3.1: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: 21.0.3.254, server: , request: "POST /invoke HTTP/1.1", host: "21.0.3.1:9000"
    21.0.3.1 21.0.3.254 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