This topic describes how to use the sample code of Alibaba Cloud SDK for Go to set the instance type for a function.

When you create or modify a function, you can use Alibaba Cloud SDK for Go to specify whether to use the flexible instance or performance instance type for your function. The backend routes your request to the specified instance type.

You can set the instance type parameter to one of the following values:
  • e1: flexible instance
  • c1: performance instance

If you do not specify an instance type, your function uses the flexible instance by default.

Sample code

//  Go sdk
package main

import (
    "github.com/aliyun/fc-go-sdk"
)

func main() {
    // new fc client
    client, _ := fc.NewClient("endpoint", "2016-08-15",
        "accessKeyID", "accessKeySecret")

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

    // CreateFunction
    functionName := "TestFunction"
    createFunctionInput := fc.NewCreateFunctionInput(serviceName).
        WithFunctionName(functionName).
        WithHandler("index.handler").
        WithRuntime("python2.7").
        WithCode(fc.NewCode().WithFiles("./code/index.py")).
        WithTimeout(5).
        WithInstanceType("c1") // Specifies that the function uses the performance instance type.
    _, err = client.CreateFunction(createFunctionInput)
    if err ! = nil {
        panic(err)
    }
    
    return
}