All Products
Search
Document Center

Function Compute:Automatically decompress files in OSS with Function Compute

Last Updated:Mar 24, 2026

This tutorial shows how to deploy a function by using Serverless Devs or the Function Compute console. Uploading a ZIP file that matches specified rules to Object Storage Service (OSS) triggers the function to automatically decompress the file.

Usage notes

  • Use UTF-8 or GB 2312 encoding for your file and folder names. Otherwise, the names of the decompressed files or folders may become garbled, or the decompression process may be interrupted.

  • When you upload a compressed file to a bucket, do not select the archive storage or cold archive storage type. Otherwise, the function cannot be triggered.

  • Use a standard ZIP command-line tool to create compressed files to prevent decompression failures.

  • Each file within the compressed archive must not exceed 1 GB. Otherwise, decompression may fail.

  • The time limit for decompressing a single archive is 2 hours. A task that exceeds this limit will fail.

  • The default execution timeout for the function is 2 hours. You can adjust this timeout to meet your business requirements.

How it works

image

Automate decompression with the Function Compute console

Prerequisites

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Applications.

  2. On the Applications page, click Create Application.

  3. On the Create Application page, select a method to create the application.

    This tutorial demonstrates the Use a Template to Create an Application option.

  4. In the templates section, select the Hot Templates tab. Find the start-unzip-oss card, hover over it, and then click Create Now.

  5. On the Create Application page, configure the following parameters and then click Create and Deploy Default Environment.

    The following table describes the key parameters. You can use the default values for other parameters.

    Parameter

    Description

    Basic configurations

    Deployment Type

    Select Directly Deploy.

    Role Name

    The default value is AliyunFCServerlessDevsRole. If the current permissions are insufficient, click Add Policy, select a policy in the dialog box, and then click Add.

    Advanced settings

    Region

    Select the region where you want to deploy the application.

    Service name

    Specify the service name for the application.

    Function name

    Specify the function name for the application.

    RAM role ARN

    Select the role that OSS uses to trigger the function. Make sure that the role has the AliyunOSSFullAccess and AliyunFCDefaultRolePolicy permission policies attached.

    OSS bucket name

    Select an existing bucket.

    Prefix

    Set the file prefix. The default is src. Different triggers in the same bucket cannot have the same file prefix.

    Decompress destination directory

    Specify the target directory for the decompressed file. The default is dst.

    Note

    To prevent a trigger loop, ensure this directory differs from the Prefix.

    Keep file name as directory

    Determines whether to create a subdirectory named after the compressed file. Valid values:

    • true: Retains the name of the compressed file as a directory in the destination path. For example, if the decompress destination directory is target and the compressed file name is source.zip, the file path after decompression is target/source/....

    • false: Extracts the files directly to the target directory. In the preceding example, the file path after extraction is target/....

    Trigger RAM role ARN

    The default value is AliyunOSSEventNotificationRole. OSS uses this role to send event notifications to invoke the function.

  6. Test the application.

    Uploading a .zip file to a path that starts with the specified Prefix triggers the application's function, which automatically decompresses the file and saves the results to the specified Decompress destination directory.

    For example, you set the prefix to source and the decompress destination directory to target. When you upload a .zip file to source or source1, the function is triggered, and the file is automatically decompressed and saved to target.

(Recommended) Automate decompression with Serverless Devs

Prerequisites

Procedure

  1. Run the following command to clone the sample project:

    git clone git@github.com:awesome-fc/decompress-oss.git
  2. Run the following command to navigate to the project directory:

    cd decompress-oss
  3. Edit the configurations in the s.yaml file and save the file.

    • In the file, change the value of the bucketName parameter from your-bucket to the name of the bucket that you created.

    • Optional: Modify the parameters for the OSS trigger prefix Prefix, the suffix Suffix, and the directory for storing decompressed files PROCESSED_DIR as needed.

    Note

    In this example, the OSS trigger prefix defaults to src/, but you can also set it to src. The destination directory for decompressed files defaults to dst/.

  4. Run the following command to deploy the project:

    sudo s fc-decompress-oss-invoke-fc-EnhancedInstance deploy -y

    Sample 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
    
    
    fc-decompress-oss-invoke-fc-EnhancedInstance:
      region:   cn-hangzhou
      service:
        name: enhancedInstance-decompress
      function:
        name:       oss-invoke-fc
        runtime:    python3
        handler:    index.handler
        memorySize: 4096
        timeout:    7200
      triggers:
        -
          type: oss
          name: zip-t
        -
          type: oss
          name: gz-t
        -
          type: oss
          name: tar-t
  5. Upload a compressed file, such as a .zip, .tar, or .gz file, to the specified directory in the bucket to trigger the decompression function.

    In this example, the default directory is src/, and the extracted files are automatically generated in dst/.

References