本文介绍使用SDK设置函数的按量实例。

SDK示例

本文以Go语言为例,可以通过以下方法指定函数的按量实例。

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)
}