You must configure Funcraft before you run fun commands. This topic describes how to configure Funcraft.

Background information

You can use three methods to configure Funcraft. The priority of the three configuration methods decreases in the following order:

Scenario

Assume that you run the fun config command to set the region parameter to cn-beijing, but a special project needs to be deployed to the China (Shanghai) region. In this case, you can create a separate .env file in the project and enter REGION=cn-shanghai in the file. Then, run the fun deploy command to deploy the project to the China (Shanghai) region. This way, you can deploy different projects to different regions.

Use a .env file

  1. In the project directory where the template.yml file is located, create a .env file.
    Note We recommend that you specify the path of the .env file in the .gitignore file to prevent account information leakage.
  2. In the .env file, enter the following configuration information:
    ACCOUNT_ID=xxxxxxxx
    REGION=cn-shanghai
    ACCESS_KEY_ID=xxxxxxxxxxxx
    ACCESS_KEY_SECRET=xxxxxxxxxx
    FC_ENDPOINT=https://{accountid}.{region}.fc.aliyuncs.com
    TIMEOUT=10
    RETRIES=3

Run the fun config command

  1. Run the following command:
    fun config
  2. Set the Aliyun Account ID, Aliyun Access Key ID, Aliyun Access Key Secret, and Default region name parameters in sequence as prompted.
    You can obtain the ID and AccessKey ID of your Alibaba Cloud account in the Common Info section of the Overview page in the Function Compute console, as shown in the following figure.fun_config_accesskey
    After the configuration is complete, Funcraft saves the configuration to the .fcli/config.yaml file.

Use environment variables

The procedure of using environment variables to configure Funcraft varies with the operating system. If you use environment variables to configure Funcraft, the configuration items are the same as those in the .env file.