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.
Step 1: Prepare the environment
The easiest way to install Funcraft is to download the executable binary files.
- Install Funcraft on the local machine. For more information, see Install Funcraft.
- Run the
fun --versioncommand to check whether the installation is successful.
- Run the
fun configcommand 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
- Run the following command to clone the sample project to your local device.
git clone https://github.com/awesome-fc/fc-custom-demoNote If you have not installed Git, download it from https://github.com/awesome-fc/fc-custom-demo and install it.
- Optional:Modify the sample code in the dart-demo directory to implement your business logic.
- Run the following command to access the cloned sample project:
cd fc-custom-demo cd dart-demo
- Run the following command to deploy the project to Function Compute:
fun deploy -yThe 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
- 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