A Funfile contains the commands that specify the steps to produce Function Compute deliverables such as the content that must be published after you develop, package, and compile a project. Funcraft runs the commands in the Funfile to produce the deliverables. This topic describes how to use a Funfile to install third-party dependencies.


Before you begin, make sure that the following operations are complete:
  • Funcraft is installed and configured. For more information, see the "Step 1: Install Funcraft" section of the Install Funcraft topic and the Configure Funcraft topic.
  • Docker is installed. For more information, see the "Step 2: (Optional) Install Docker" section of the Install Funcraft topic.

Syntax supported by Funfiles

Funfiles support specific commands in Dockerfiles, such as the COPY, RUN, ENV, USER, and WORKDIR commands A Dockerfile is used to build a Docker image, whereas a Funfile is used to produce Function Compute deliverables. You can install the rlang package to check the commands that are supported by Funfiles. For more information, see rlang.

To use a Funfile to install third-party dependencies, add fun-install before the original apt-get and pip commands, which are used in a Dockerfile, in the Funfile.

Benefits of Funfiles

  • Standardized: The commands that are specified in a Funfile to install dependencies help standardize the development process.
  • Convenient: You can submit a Funfile instead of specific dependencies to the version control system. This helps maintain function code.
  • Native: Funfile commands are similar to native Dockerfile commands, but provide better user experience. You can test installation commands in an interactive environment by using the fun install sbox command and then write the final installation commands in a Funfile.
  • Efficient: Funfiles support the cache feature of Dockerfiles. If the changes in a project do not affect Funfiles, Function Compute can skip related commands in the Funfiles based on the cached data. This accelerates the execution of Funfiles and improves development efficiency.


  1. Create a Funfile.
    1. In the project directory, run the fun install init command to initialize the Funfile.
    2. Select a runtime environment for function execution.
      ? Select a runtime (Use arrow keys)
      > nodejs6
      (Move up and down to reveal more choices)
      In this topic, the value python2.7 is selected to provide an example on how to install third-party dependencies. After you select python2.7, a file named Funfile is generated in the current directory. The file contains the following content:
      RUNTIME python2.7
      Note A Funfile is a text file. You can specify a runtime environment in the Funfile based on your requirements.
  2. Use the Funfile to install a dependent pip package.
    1. Configure the following content in the Funfile:
      RUNTIME python2.7
      RUN fun-install pip install flask                    
      Note If you want to install a dependent apt package, replace pip in the preceding content with apt-get in the Funfile.
    2. Run the following command to install dependencies:
      fun install
      The following sample code shows the expected output:
      using template: template.yml
      start installing function dependencies without docker
      building pyzbar-srv/pyzbar-fun
      Funfile exist, Fun will use container to build forcely
      Step 1/2 : FROM aliyunfc/runtime-python3.6:build-1.6.1
       ---> 2110e9fa9393
      Step 2/2 : RUN fun-install pip install flask
       ---> Using cache
       ---> 992b0d65136d
      Successfully built 992b0d65136d
      Successfully tagged fun-cache-e95a9bfa-a6fa-4d70-b5b4-0084613e2b8d:latest
      copying function artifact to /Users/tan/code/fun/examples/install/pyzbar_example
      could not find any manifest file for pyzbar-srv/pyzbar-fun, [install] stage for manifest will be skipped
      Tips for next step
      * Invoke Event Function: fun local invoke
      * Invoke Http Function: fun local start
      * Build Http Function: fun build
      * Deploy Resources: fun deploy                    


The dependencies installed by using the fun install command are installed to the code directory. You can use the fun local command to perform on-premises debugging and use the fun deploy command to deploy your project to the cloud.