本文介绍如何使用Go SDK中的示例代码设置实例类型。
您可以通过SDK在创建函数或更新函数时指定使用弹性实例还是性能实例,系统后端会将您的请求路由至设置的实例类型中。
实例类型参数为:
- e1:弹性实例
- c1:性能实例
如果不指定实例类型,则默认为弹性实例。
SDK示例
// 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") // 指定函数所属实例类型为性能实例。
_, err = client.CreateFunction(createFunctionInput)
if err != nil {
panic(err)
}
return
}