This topic describes how to use the SDK to create a pay-as-you-go instance for a function.
SDK code samples
This topic describes how to specify a pay-as-go instance for a function in Go language by using the following methods:
package main
import (
"fmt"
fc "https://github.com/aliyun/fc-go-sdk"
)
const (
endpoint = "your-endpoint"
fcAPIVersion = "2016-08-15"
AccessKeyID = "your-ak-id"
AccessKeySecret = "your-ak-secret"
)
var (
serviceName = "service-name"
qualifier = "LATEST"
functionName = "function-name"
)
func main() {
fcClient, _ := fc.NewClient(endpoint, fcAPIVersion, AccessKeyID, AccessKeySecret)
// set
putInput := fc.NewPutOnDemandConfigInput(serviceName, qualifier, functionName)
putInput.WithMaximumInstanceCount(10)
putResp, err := fcClient.PutOnDemandConfig(putInput)
fmt.Println("put on-demand config", putResp, err)
// list
listInput := fc.NewListOnDemandConfigsInput()
listInput.WithPrefix(fmt.Sprintf("services/%s", serviceName))
listResp, err := fcClient.ListOnDemandConfigs(listInput)
fmt.Println("list on-demand configs", listResp, err)
// get
getInput := fc.NewGetOnDemandConfigInput(serviceName, qualifier, functionName)
getResp, err := fcClient.GetOnDemandConfig(getInput)
fmt.Println("get on-demand configs", getResp, err)
// delete
deleteInput := NewDeleteOnDemandConfigInput(serviceName, qualifier, functionName)
deleteResp, err := fcClient.DeleteOnDemandConfig(deleteInput)
fmt.Println("delete on-demand configs", deleteResp, err)
}