本文介绍使用SDK创建Custom Container函数。
SDK示例
本文以使用Go SDK创建Custom Container函数为例:
package main
import (
"fmt"
"os"
"github.com/aliyun/fc-go-sdk"
)
func main() {
fcClient, err := fc.NewClient(fmt.Sprintf("%s.cn-shanghai.fc.aliyuncs.com", os.Getenv("ACCOUNT_ID")),
"2016-08-15", os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_ID_SECRET"))
if err != nil {
panic(err)
}
// Create a function, with CustomContainerConfig.AccelerationType to be Default,
// which enables image pull acceleration
respC, err := fcClient.CreateFunction(fc.NewCreateFunctionInput("demo-service").
WithFunctionName("demo-function").
WithHandler("bootstrap").
WithRuntime("custom-container").
WithCustomContainerConfig(fc.NewCustomContainerConfig().
WithImage("registry.cn-shenzhen.aliyuncs.com/fc-demo/nodejs-express:v1").
WithAccelerationType("Default")))
if err != nil {
panic(err)
}
fmt.Printf("FC CreateFunction response: %+v\n", *respC)
// Update a function, with CustomContainerConfig.AccelerationType to be None,
// which disables image pull acceleration
respU, err := fcClient.UpdateFunction(fc.NewUpdateFunctionInput("demo-service", "demo-function").
WithCustomContainerConfig(fc.NewCustomContainerConfig().
WithImage("registry.cn-shenzhen.aliyuncs.com/fc-demo/nodejs-express:v1").
WithAccelerationType("")))
if err != nil {
panic(err)
}
fmt.Printf("FC UpdateFunction response: %+v\n", *respU)
}
镜像拉取加速说明
镜像拉取加速的配置项说明如下:
在调用CreateFunction或UpdateFunction创建或更新函数时,配置CustomContainerConfig结构中的accelerationType参数(String类型),取值如下:
Default
:开启镜像拉取加速。None
:关闭镜像拉取加速。