Object Storage Service (OSS) can automatically decompress ZIP files. If you want to decompress files in other formats, such as TAR and GZ, you can create an OSS event trigger in Function Compute and write the logic code of functions. This topic describes how to automatically decompress a file and upload the file to OSS by using the Function Compute console and Serverless Devs. In this topic, Python 3.6 is used as an example.

Background information

The following flowchart shows the decompression process.principle
Note We recommend that you run the standard ZIP and TAR commands to compress files.

(Recommended) Use Serverless Devs to automatically decompress files


  1. Activate the Function Compute and OSS services.
  2. Create a bucket
  3. Install Serverless Devs
  4. Configure Serverless Devs
  5. Install Git.


  1. Run the following command to download a demo project:
    git clone https://github.com/awesome-fc/decompress-oss.git
  2. Run the following command to go to the project directory:
    cd decompress-oss
  3. Edit the configuration information in the s.yaml file and save the file.
    • Change the value of the bucketName parameter from your-bucket to the name of your OSS bucket.
    • Optional: Change the values of the Prefix, Suffix, and PROCESSED_DIR parameters based on your business requirements. PROCESSED_DIR specifies the directory that stores the decompressed files.
    Note In the examples of this topic, the prefix for the OSS event trigger is src/. You can also use the src prefix. By default, the directory that stores the decompressed files is dst/.
  4. Run the following command to deploy the project:
    s fc-decompress-oss-invoke-fc-EnhancedInstance deploy -y
    Sample command output:
     Checking Service, Function, Triggers (18.63s)
     Creating Service, Function, Triggers (13.44s)
    There is auto config in the service: enhancedInstance-decompress
    Tips for next step
    * Display information of the deployed resource: s info
    * Display metrics: s metrics
    * Display logs: s logs
    * Invoke remote function: s invoke
    * Remove Service: s remove service
    * Remove Function: s remove function
    * Remove Trigger: s remove trigger
    * Remove CustomDomain: s remove domain
      region:   cn-hangzhou
        name: enhancedInstance-decompress
        name:       oss-invoke-fc
        runtime:    python3
        handler:    index.handler
        memorySize: 4096
        timeout:    7200
          type: oss
          name: zip-t
          type: oss
          name: gz-t
          type: oss
          name: tar-t
  5. After you deploy the project, you can upload the compressed files with extensions such as .zip, .tar, and .gz to a specified directory in your OSS bucket. In the example of this topic, the default directory is src/. After you upload the files, a function is triggered to decompress the files.
    The function automatically decompresses the files to the specified directory. The default directory that is used to store decompressed files is /dst.

Use the Function Compute console to automatically decompress files

If a compressed file is large in size and contains multiple files, the decompression may time out and fail. Together with Serverless Workflow, Function Compute can decompress a file that contains a large number of files by using the following solution.


  1. Activate the Function Compute and OSS services.
  2. Create a bucket
  3. Configure decompression rules for ZIP packages


  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Application Store.
  3. On the Application Center page that appears, click the Real-time File Processing tab in the Application Templates section.
  4. On the Real-time File Processing tab, choose Unzip OSS File > Configure and Deploy.
  5. On the Create Template Application page, configure the parameters and click Deploy.
    Note You can use this solution only in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Shenzhen), Singapore (Singapore), and US (Silicon Valley). This solution takes effect on only ZIP files.

    If this solution does not meet your requirements for decompressing large files, contact us.