All Products
Search
Document Center

Function Compute:Compile and deploy a code package

Last Updated:Apr 01, 2026

Go is a statically compiled language. Function Compute does not support editing Go code directly in the console, so you must compile your application locally, package the binary into a .zip file, and then upload it.

Prerequisites

Before you begin, ensure that you have:

  • The Go development environment installed (Go 1.8 or later). Function Compute supports Go 1.x.

How it works

  1. Write your Go function using the Function Compute SDK for Go.

  2. Compile the source file locally into a Linux-compatible binary.

  3. Package the binary into a .zip file.

  4. Create an event-triggered function in the Function Compute console, upload the .zip file, and set Handler to the name of the compiled binary.

The Handler field must match the compiled binary name exactly. If the binary is named main and is in the root of the .zip file, set Handler to main. If it is in a subdirectory such as bin/, set Handler to bin/main. Function Compute executes this binary directly when the function is invoked.

Compile and package on Linux or macOS

  1. Download the Function Compute SDK for Go.

    go get github.com/aliyun/fc-runtime-go-sdk/fc
  2. Create a source file (for example, main.go), then build the binary. Use the command that matches your machine: Linux (x86-64) — build a statically linked binary to avoid external dependencies such as libc:

    GOOS=linux CGO_ENABLED=0 go build main.go

    macOS with Apple silicon (M1) — cross-compile for the x86-64 architecture used by Function Compute:

    GOOS=linux GOARCH=amd64 go build main.go

    macOS with Intel — set GOOS=linux to produce a Linux-compatible binary:

    GOOS=linux go build main.go

    After the build, a binary with the same name as your source file is created in the current directory.

  3. Package the binary into a .zip file.

    zip fc-golang-demo.zip main

Compile and package on Windows

  1. Create a source file such as main.go, then open Command Prompt: press Win+R, type cmd, and press Enter.

  2. Build the binary.

    set GOOS=linux
    set GOARCH=amd64
    go build -o main main.go

    After the build, a binary named main is created in the current directory.

  3. Use the build-fc-zip tool to package the binary. On Windows, use this tool instead of the native zip command to preserve file permissions.

    1. Install build-fc-zip.

      set GOOS=windows
      set GOARCH=amd64
      go install github.com/aliyun/fc-runtime-go-sdk/cmd/build-fc-zip@latest

      The tool is installed to %USERPROFILE%\go\bin by default.

    2. Package the binary.

      %USERPROFILE%\go\bin\build-fc-zip.exe -output main.zip main

Create a function and configure the handler

  1. Create an event-triggered function. For Runtime, select Go 1.

  2. Upload your code package and configure the handler. For details, see Create an event function. In the Handler configuration on the Function Compute console, the Handler for a Go FC function must be set directly to [filename]. This filename is the name of the compiled binary file.

    • If the binary is in the root of the .zip package, set Handler to main.go-main

    • If the binary is in a subdirectory such as bin/, set Handler to bin/main.gp-bin-main