To automatically decompress compressed files that you upload to Object Storage Service (OSS), you can deploy an application with a single click from the Function Compute Application Center. When a ZIP file that matches a decompression rule is uploaded to Object Storage Service, a Function Compute function is automatically triggered to decompress the file. After the file is decompressed, Function Compute uploads the extracted files to a specified directory in Object Storage Service.
Background information
The following flowchart shows the process.
Notes
Use UTF-8 or GB 2312 encoding for file and folder names. This prevents garbled text or interruptions during decompression.
When you upload a compressed file to a bucket, do not select Archive Storage or Cold Archive as the storage class. Otherwise, the function cannot be triggered.
A single file within the compressed archive that you upload to a bucket must not exceed 1 GB. If a file is larger than 1 GB, the decompression may fail.
The maximum decompression time for a single archive is 2 hours. The task fails if it exceeds this time limit.
The default function execution timeout is 2 hours. You can adjust the function execution timeout period as needed.
Prerequisites
Function Compute is activated. For more information, see Activate Function Compute.
Object Storage Service (OSS) is activated and a bucket is created. For more information, see Create a bucket.
Procedure
Log on to the Function Compute console. In the left-side navigation pane, click Applications.
-
On the Applications page, click Create Application. Then, on the Create Application page, select a creation method.
This topic uses Use a Template to Create an Application as an example.
-
On the Create Application page, in the templates section, find the Auto-decompress ZIP Files Uploaded To OSS card. Hover your pointer over the card and click Create Now.
-
On the Create Application page, configure the following parameters and then click Create and Deploy Default Environment.
The following table describes the main configuration items. You can use the default values for the other items.
Configuration Item
Description
Basic Configurations
Deployment Type
Select Directly Deploy.
Role Name
The default role is AliyunFCServerlessDevsRole. If the current permissions are insufficient, click Add Policy, select the required policy in the dialog box and click Add.
Advanced Settings
RAM role ARN
Select the role that OSS uses to trigger the function. Make sure that the AliyunOSSFullAccess and AliyunFCDefaultRolePolicy access policies are attached to this role.
OSS bucket name
Select the created bucket.
Prefix
Set the file prefix. The default value is src.
ImportantMake sure that the prefixes for different triggers in the same bucket are unique. Otherwise, the application fails to be created.
Destination directory
Set the destination directory for the decompressed files. The default value is dst.
NoteTo prevent the function from being triggered in a loop, set this directory to a different path from the one specified for Prefix.
Keep archive name as directory
Specifies whether to keep the compressed file name as a directory in the path. Valid values:
-
true: Creates a subdirectory. For example, if the Destination Directory is target and the archive is named source.zip, the extracted files are saved to target/source/....
false: Decompresses the files directly into the destination directory. In the preceding example, the path of the decompressed files is target/....
Trigger RAM role ARN
The default role is AliyunOSSEventNotificationRole. OSS uses this role to send event notifications to invoke the function.
-
-
Test the application.
Log on to the Object Storage Service (OSS) console and click the bucket that you selected when you created the application.
-
In the selected bucket, upload a .zip file to a path that starts with the configured Prefix. This triggers the function to automatically decompress the file and save its contents to the specified Destination Directory.
For example, if you set Prefix to source and Destination Directory to target, uploading a .zip file to a path such as source/data.zip or source1/test.zip triggers the function. The extracted files are then saved to the target directory.
References
The one-click deployment application described in this topic supports only the decompression of ZIP files. To decompress files in other formats, see decompress-oss.
If you only need to decompress ZIP files uploaded to OSS, you can configure automatic ZIP file decompression directly in OSS. For more information, see Upload and automatically decompress a ZIP package.
To use Function Compute to package and download files from OSS, see Package multiple files into a ZIP archive for download.