This topic provides an example on how to create a custom container function by using an SDK.

SDK example

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")))
    if err != nil {
        panic(err)
    }
    fmt.Printf("FC CreateFunction response: %+v\n", *respC)

}