Creating an Instance
This section describes how to create an instance using AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. Set the Name and Model parameters in the initialized CreateInstanceReq command to configure the instance name and model. After the configuration is complete, run the code.
- The sample code for creating an instance is as follows:
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" imagesearch "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/imagesearch/v1/region" ) func main() { // Set the obtained AK and SK. ak := "<YOUR AK>" sk := "<YOUR SK>" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() //Set the request client. In this example, CN North-Beijing4 is used. client := imagesearch.NewImageSearchClient( imagesearch.ImagesearchClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) //Set the instance name and model. request := &model.RunCreateInstanceRequest{} tags := []string{"animal", "plant"} request.Body = &model.CreateInstanceReq{ Name: "instance-name", Model: "common-search", Tags: &tags, } response, err := client.RunCreateInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
- If the instance creation result is displayed on the console, the code is successfully executed. For details, see Creating an Instance.
RunCreateInstanceResponse{"domain": " general image search ","desc":"","registerDate":1638321711363,"expiredDate":-1,"level":30000000,"status":"NORMAL","instanceName":"instance-name"}
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot