All Products
Document Center

Use fun build to build packages

Last Updated: Mar 27, 2020

In many scenarios, source code cannot directly produce deliverables. For example, Java code must be compiled and packaged first. Function Compute can accept ZIP or JAR packages as deliverables. You must package the compiled source code and dependencies into a JAR package. The fun build command is used to build deliverables from source code.


You can run the fun build -h command to view the description, syntax, and parameters:

  1. $fun build -h
  2. Usage: fun build [options] [[service/]function]
  3. Build the dependencies.
  4. Options:
  5. -u, --use-docker Use docker container to build functions
  6. -t, --template [template] path of fun template file.
  7. -h, --help output usage information

To compile a function, run the fun build serviceName/functionName or fun build functionName command.

By default, deliverables are build on the host. To avoid incompatibility errors with the host, you can specify the -u or —use-docker parameter to compile within a simulated local Function Compute environment.

If the template.yml file is not in the current directory, you can use fun build -t templatePath to specify the path.

If you do not specify a function to be built, all functions in the template.yml file will be built by default.


  1. # Use fun build to build all functions.
  2. fun build
  3. # Use fun build to build all functions within the local simulation environment.
  4. fun build --use-docker
  5. # Use fun build to build functions. After the functions are built, call the functions.
  6. fun build && fun local invoke
  7. # Use fun build to build functions. After the functions are built, deploy the functions.
  8. fun build && fun deploy


When you run the fun build command, specific manifest files will be searched in the code directory. Then, download and compiling operations are performed based on the manifest files.

Fun supports the following manifest files of mainstream package managers.

  1. Language-unlimited fun-defined Funfile
  2. pom.xml of Apache Maven for Java
  3. package.json of npm for Node.js
  4. requirements.txt of pip for Python
  5. composer.json of Composer for PHP

For example, the following template.yml file contains functions that can be run in PHP 7.2, Python 2.7, Python 3, Node.js 6, Node.js 8, and Java 8 runtimes.

  1. // Other attributes are omitted.
  2. Resources:
  3. localdemo:
  4. Type: 'Aliyun::Serverless::Service'
  5. php72:
  6. Type: 'Aliyun::Serverless::Function'
  7. Properties:
  8. Runtime: php7.2
  9. // Other attributes are omitted.
  10. python27:
  11. Type: 'Aliyun::Serverless::Function'
  12. Properties:
  13. Runtime: python2.7
  14. // Other attributes are omitted.
  15. python3:
  16. Type: 'Aliyun::Serverless::Function'
  17. Properties:
  18. Runtime: python3
  19. // Other attributes are omitted.
  20. nodejs6:
  21. Type: 'Aliyun::Serverless::Function'
  22. Properties:
  23. Runtime: nodejs6
  24. // Other attributes are omitted.
  25. nodejs8:
  26. Type: 'Aliyun::Serverless::Function'
  27. Properties:
  28. Runtime: nodejs8
  29. // Other attributes are omitted.
  30. java8:
  31. Type: 'Aliyun::Serverless::Function'
  32. Properties:
  33. Runtime: java8
  34. // Other attributes are omitted.

When you run fun build, functions will be built sequentially and deliverables will be stored in .fun/build/artifacts/ in the root directory of the project.


Java example

The following example shows how to use Fun to initialize, build, run, and modify a function in Java.



You can use the fun build command to build deliverables from source code to save configuration costs.