You can use the custom runtime of Function Compute to write functions in Dart. This topic describes how to quickly deploy and call a Dart function. You can modify the Dart code.

Prerequisites

You have installed Node.js 8.6.0 or later. For more information, see the official download page.
Note If you have installed Funcraft, go to Step 2: Deploy and call a function.

Step 1: Prepare the environment

The easiest way to install Funcraft is to download the executable binary files.

  1. Install Funcraft on the local machine. For more information, see Install Funcraft.
  2. Run the fun --version command to check whether the installation is successful.
  3. Run the fun config command to configure Funcraft. Set the Account ID, Access Key ID, Access Key Secret, and Default region name parameters 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

  1. Run the following command to clone the sample project to your local device.
    git clone https://github.com/awesome-fc/fc-custom-demo          
    Note If you have not installed Git, download it from https://github.com/awesome-fc/fc-custom-demo and install it.
  2. Optional:Modify the sample code in the dart-demo directory to implement your business logic.
  3. Run the following command to access the cloned sample project:
    cd fc-custom-demo
    cd dart-demo
  4. Run the following command to deploy the project to Function Compute:
    fun deploy -y
    The following results are returned:
    Waiting for service dart-demo to be deployed...
            Waiting for function dart-func to be deployed...
                    Waiting for packaging function dart-func code...
                    The function dart-func has been packaged. A total of 2 files were compressed and the final size was 2.57 MB
            function dart-func deploy success
    service dart-demo deploy success
  5. Run the following command to call the deployed function:
    fun invoke -e "Hello World"
    The following results are returned:
    ========= FC invoke Logs begin =========
    FC Invoke Start RequestId: 81d9e365-7f42-46e6-b27f-7981d16303b6
    hello world
    FC Invoke End RequestId: 81d9e365-7f42-46e6-b27f-7981d16303b6
    
    Duration: 1.08 ms, Billed Duration: 100 ms, Memory Size: 1024 MB, Max Memory Used: 17.50 MB
    ========= FC invoke Logs end =========
    
    FC Invoke Result:
    Hello World