Fix "permission denied" errors when running executables in Function Compute

更新时间:
复制 MD 格式

Symptom

A function runs correctly on an on-premises Windows or macOS machine but fails with a permission denied error after deployment to Function Compute.

Cause

Function Compute runs code in a Linux runtime. When you package code on Windows or macOS, some compression tools strip POSIX file attributes, including executable permissions (such as 755). After decompression, the system cannot run files that lack execute permission.

To prevent this issue, verify that executable files have the correct permissions (such as 755) before packaging and ensure your compression tool retains POSIX file attributes.

Solutions

If you have already deployed a package with missing executable permissions, use one of the following methods. Solutions are listed from quickest to most involved.

Solution 1: Grant permissions through WebIDE

  1. Log on to the Function Compute console.

  2. Open the function in WebIDE and launch the terminal. For more information, see What is WebIDE?.

  3. Run the following command to grant execute permission to the file:

    chmod +x <file_name>
  4. Save and redeploy the function.

Solution 2: Use Windows Subsystem for Linux (WSL)

If you develop on Windows, use Windows Subsystem for Linux (WSL) to package your code. WSL preserves file permissions during compression. Make sure you work within the WSL filesystem rather than on a Windows-mounted drive.

Solution 3: Develop on a Linux operating system

Use a Linux operating system for on-premises development. Linux preserves POSIX file attributes natively, so executable permissions are retained during packaging and deployment.

Solution 4: Use a custom container runtime

Deploy your function as a custom container image. A Dockerfile explicitly sets file permissions, which eliminates permission issues caused by compression tools. This approach requires familiarity with Docker and a container registry such as Alibaba Cloud Container Registry.