NavigationContentFooter
Jump toSuggest an edit

Scaleway Go software development kit (SDK)

Reviewed on 27 November 2024Published on 14 November 2023

The Scaleway Go SDK is an evolving tool provided by Scaleway for developers to interact with its cloud services using the Go programming language.

It simplifies tasks like server management, storage operations, and networking setup by handling complex API calls and authentication processes.

This SDK is a valuable tool for integrating Scaleway’s cloud resources into applications or managing them programmatically.

Important

The SDK is in its early release stage, which means the API might change.

Installation of the Go SDK

To use the SDK, you can install it using go get github.com/scaleway/scaleway-sdk-go. The process involves creating a Scaleway client, and then using SDK objects for various Scaleway services.

Initialization

You need a pair of access and secret keys to connect to Scaleway API. Check out the documentation to find out how to retrieve them.

A minimal setup, allowing you to list servers using the Instance API, would look like this:

package main
import (
"fmt"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/scaleway-sdk-go/utils"
)
func main() {
// Create a Scaleway client
client, err := scw.NewClient(
// Get your organization ID at https://console.scaleway.com/organization/settings
scw.WithDefaultOrganizationID("SCW_DEFAULT_ORGANIZATION_ID"),
// Get your credentials at https://console.scaleway.com/iam/api-keys
scw.WithAuth("SCW_ACCESS_KEY", "SCW_SECRET_KEY"),
// Get more about our availability zones at https://www.scaleway.com/en/docs/console/account/reference-content/products-availability/
scw.WithDefaultRegion("SCW_REGION"),
)
if err != nil {
panic(err)
}
// Create SDK objects for Scaleway Instance product
instanceApi := instance.NewAPI(client)
// Call the ListServers method on the Instance SDK
response, err := instanceApi.ListServers(&instance.ListServersRequest{
Zone: scw.ZoneFrPar1,
})
if err != nil {
panic(err)
}
// Do something with the response...
for _, server := range response.Servers {
fmt.Println("Server", server.ID, server.Name)
}
}

Example

To create a Kubernetes cluster on Scaleway using the Go SDK, you would typically interact with the scaleway SDK package. The specific details can change, so you should always refer to the latest documentation. Below is a conceptual example of how you might use the Scaleway Go SDK to create a Kubernetes (Kapsule) cluster with 3 nodes:

package main
import (
"fmt"
"log"
"time"
scaleway "github.com/scaleway/scaleway-sdk-go/scw"
k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
vpc "github.com/scaleway/scaleway-sdk-go/api/vpc/v2"
)
// Edit these values towards your Scaleway credentials, the Kubernetes version and the type of nodes you want to use.
const (
accessKey = "<access_key>"
secretKey = "<secret_key>"
projectID = "<project_id>"
region = "fr-par"
zone = "fr-par-1"
clusterName = "my-k8s-cluster"
nodeType = "PLAY2-NANO"
numberOfNodes = 3
kubernetesVersion = "1.28.2"
)
func main() {
client, err := createClient()
if err != nil {
log.Fatalf("Failed to initiate Scaleway client: %v", err)
}
k8sAPI := k8s.NewAPI(client)
vpcAPI := vpc.NewAPI(client)
pnID, err := createPrivateNetwork(vpcAPI)
if err != nil {
log.Fatalf("Failed to create Private Network: %v", err)
}
fmt.Printf("Private Network created with ID: %s\n", pnID)
time.Sleep(5 * time.Second) // Sleep for 5 seconds for the resource to become available
clusterID, err := createCluster(k8sAPI, pnID)
if err != nil {
log.Fatalf("Failed to create Kubernetes cluster: %v", err)
}
fmt.Printf("Cluster created with ID: %s\n", clusterID)
time.Sleep(5 * time.Second) // Sleep for 5 seconds for the resource to become available
nodePoolID, err := createNodePool(k8sAPI, clusterID)
if err != nil {
log.Fatalf("Failed to create node pool: %v", err)
}
fmt.Printf("Node pool created with ID: %s\n", nodePoolID)
}
// Initialize the Scaleway client
func createClient() (*scw.Client, error) {
return scaleway.NewClient(
scaleway.WithAuth(accessKey, secretKey),
scaleway.WithDefaultProjectID(projectID),
scaleway.WithDefaultRegion(region),
scaleway.WithDefaultZone(zone),
)
}
// Create a Private Network
func createPrivateNetwork(vpcAPI *vpc.API) (string, error) {
pn, err := vpcAPI.CreatePrivateNetwork(&vpc.CreatePrivateNetworkRequest{
Region: region,
ProjectID: projectID,
Tags: []string{"kube-cluster-pn"},
})
if err != nil {
return "", err
}
return pn.ID, nil
}
// Create a Kubernetes Kapsule cluster
func createCluster(k8sAPI *k8s.API, pnID string) (string, error) {
cluster, err := k8sAPI.CreateCluster(&k8s.CreateClusterRequest{
Type: "kapsule",
Name: clusterName,
Version: kubernetesVersion,
Region: region,
Description: clusterName,
Tags: []string{"my-cluster"},
PrivateNetworkID: &pnID,
})
if err != nil {
return "", err
}
return cluster.ID, nil
}
// Create a Kubernetes NodePool
func createNodePool(k8sAPI *k8s.API, clusterID string) (string, error) {
minSizeValue := uint32(1) // Minimum number of nodes in the pool (1)
maxSizeValue := uint32(5) // Maximum number of nodes in the pool (5)
rootVolumeSize := scw.Size(20000000000) // Size of the root file system (20GB)
nodePool, err := k8sAPI.CreatePool(&k8s.CreatePoolRequest{
ClusterID: clusterID,
Name: fmt.Sprintf("%s-pool", clusterName),
NodeType: nodeType,
RootVolumeSize: &rootVolumeSize,
Size: numberOfNodes,
MinSize: &minSizeValue,
MaxSize: &maxSizeValue,
Autoscaling: true,
Tags: []string{"my-node-pool"},
Region: region,
ContainerRuntime: "containerd",
Autohealing: true,
RootVolumeType: "b_ssd",
})
if err != nil {
return "", err
}
return nodePool.ID, nil
}

Further resources

For further information about the Scaleway Go SDK, refer to the official SDK repository.

Additional documentation is available on GoDoc and Scaleway’s developer website. These resources include API documentation and various examples for different use cases.

Was this page helpful?
API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2024 – Scaleway