This topic describes how to use the sample code in the SDK for Go to specify the instance type.

You can use an SDK to specify whether to use elastic instances or performance instances when you create or update a function. Then, the system routes your requests to the specified instance type.

The following items describe the values of the instance type parameter:
  • e1: elastic instances
  • c1: performance instances

If you do not configure the instance type parameter, elastic instances are used by default.

SDK sample code

//  Go sdk
package main

import (

func main() {
    // new fc client
    The AccessKey pair of an Alibaba Cloud account can be used to access all API operations. Using these credentials to perform operations in Function Compute is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    We recommend that you do not save the AccessKey ID and AccessKey secret to your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. 
    In this example, the AccessKey pair is saved to the environment variables for authentication. 
    Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables before you run the sample code. 
    In the runtime environments of Function Compute, the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are automatically configured after you configure the execution permissions. 
    accessKeyID := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
    accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
    client, _ := fc.NewClient("endpoint", "2016-08-15",
        accessKeyID, accessKeySecret)

    // CreateService
    serviceName := "TestService"
    _, err := client.CreateService(fc.NewCreateServiceInput().
    if err != nil {

    // CreateFunction
    functionName := "TestFunction"
    createFunctionInput := fc.NewCreateFunctionInput(serviceName).
        WithInstanceType("c1") // Specifies that the function uses performance instances. 
    _, err = client.CreateFunction(createFunctionInput)
    if err != nil {