You can use the custom runtime of Function Compute to write Dart functions in Function Compute. This topic describes how to deploy and invoke a Dart function. You can modify the sample Dart 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.
  • Install Docker. For more information, visit Docker Hub.
Note The examples in this topic apply to scenarios where Docker is installed. If you do not want to use Docker, you must install .NET Core 3.1. For more information about how to install .NET Core 3.1, see dot.net.core3.1. For more information about the commands of .NET Core 3.1, see fc-custom-demo.

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 dart-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 fc-custom-demo directory:
      cd fc-custom-demo
    2. Run the following command to go to the dart-demo directory:
      cd dart-demo
  4. Run the following command to build the bootstrap:
    make deploy
    The following output is returned:
    docker run --rm -it -v $(pwd):/tmp google/dart:2.8.4 bash -c "export PUB_HOSTED_URL=https://pub.flutter-io.cn && cd tmp/code && dart2native index.dart && mv index.exe bootstrap"
    Generated: /tmp/code/index.exe
    chmod +x code/bootstrap
  5. Run the following command to deploy the project to Function Compute:
    fun deploy -y
    The following output is 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
  6. 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: 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