Introducing Scaleway NextGen NVMe Cloud Servers with Hot-Snapshots. 🚀

Help


Community tutorials and documentations

Scaleway Command Line Interface Essentials

Overview

Scaleway CLI (Command Line Interface) helps you manage your Scaleway cloud environment. The command line interface is an essential tool to operate in a cloud environment as it allows you to administer, execute and monitor your resources faster. Scaleway CLI is easy to use and offers many commands to interact with infrastructure such as login, creating servers, attaching volumes, moving IP addresses, fetching the logs and many others.

Learn more about the Scaleway Command Line interface on our github repository

Requirements:

Setting up your Environment

By using the static-compiled release binaries, you need to have one of the following platform and architecture:

PlatformArchitecture
Mac OS Xi386, x86_64
FreeBSDarm, i386, x86_64
Windowsx86_64
Linuxarm, armv7, armv7, i386, x86_64

The Scaleway CLI is written in Go. If you do not have it installed on your computer yet, you can retrieve any version >= 1.5 from the official Golang Website.

OPTION 1: (Recommended) Using Brew

1 . Install brew https://brew.sh/index_fr

2 . Configure brew to use third party modules and download the package information

brew tap scaleway/scaleway
brew install scaleway/scaleway/scw --HEAD

3 . Configure the CLI to use your token and organization ID. You can get them in the credentials section of the Scaleway console (the organization is sometimes referenced as access key).

$ scw login --token=<your_secret_key> --organization=<your_access_key>

OPTION 2: Using Go

1 . Configure Go to use third party modules and download the package information

GO15VENDOREXPERIMENT=1 go get -u github.com/scaleway/scaleway-cli/cmd/scw

2 . Configure the CLI to use your token and organization ID. You can get them in the credentials section of the Scaleway console (the organization is sometimes referenced as access key).

$ scw login --token=<your_secret_key> --organization=<your_access_key>

Installing Scaleway Command Line Interface

  • (Recommended) On Mac OS using Homebrew and launching brew install scw

  • On Mac OS using a manual install
    Install the latest stable release on Mac OS X manually:
    # prepare for first install and upgrade
    mkdir -p /usr/local/bin
    mv /usr/local/bin/scw /tmp/scw.old
    # get latest release
    wget "https://github.com/scaleway/scaleway-cli/releases/download/v1.16/scw-darwin-amd64" -O /usr/local/bin/scw
    # test
    scw version
    Install the latest release on Linux:
    # get latest release
    export ARCH=amd64  # can be 'i386', 'amd64' or 'armhf'
    wget "https://github.com/scaleway/scaleway-cli/releases/download/v1.16/scw_1.16_${ARCH}.deb" -O /tmp/scw.deb
    dpkg -i /tmp/scw.deb && rm -f /tmp/scw.deb
    # test
    scw version
    
  • On Windows by downloading the .exe

Using Scaleway Command Line Interface

$ scw
Usage: scw [OPTIONS] COMMAND [arg...]

Interact with Scaleway from the command line.

Options:
 -h, --help=false             Print usage
 -D, --debug=false            Enable debug mode
 -V, --verbose=false          Enable verbose mode
 -q, --quiet=false            Enable quiet mode
 --sensitive=false            Show sensitive data in outputs, i.e. API Token/Organization
 -v, --version=false          Print version information and quit
 --region=par1                Change the default region (e.g. ams1)

Commands:
    help      help of the scw command line
    attach    Attach to a server serial console
    commit    Create a new snapshot from a server's volume
    cp        Copy files/folders from a PATH on the server to a HOSTDIR on the host
    create    Create a new server but do not start it
    events    Get real time events from the API
    exec      Run a command on a running server
    history   Show the history of an image
    images    List images
    info      Display system-wide information
    inspect   Return low-level information on a server, image, snapshot, volume or bootscript
    kill      Kill a running server
    login     Log in to Scaleway API
    logout    Log out from the Scaleway API
    logs      Fetch the logs of a server
    port      Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
    products  Display products information
    ps        List servers
    rename    Rename a server
    restart   Restart a running server
    rm        Remove one or more servers
    rmi       Remove one or more image(s)/volume(s)/snapshot(s)
    run       Run a command in a new server
    search    Search the Scaleway Hub for images
    start     Start a stopped server
    stop      Stop a running server
    tag       Tag a snapshot into an image
    top       Lookup the running processes of a server
    version   Show the version information
    wait      Block until a server stops

Run 'scw COMMAND --help' for more information on a command.

Scaleway CLI Quick Start

1 . Login to your server

$ scw login
Login (cloud.scaleway.com): xxxx@xx.xx
Password:
$

2 . Run a new server my-ubuntu

$ scw run --name=my-ubuntu ubuntu-trusty bash
   [...] wait about a minute for the first boot
root@my-ubuntu:~#

Scaleway CLI Subcommands

You will find below an exhaustive list of Scaleway CLI subcommands.

  • attach [OPTIONS] SERVER The scw attach [OPTIONS] SERVER subcommand connects to a running server serial console
Options:

  -h, --help=false      Print usage
  --no-stdin=false      Do not attach stdin

Examples:

    $ scw attach my-running-server
    $ scw attach $(scw start my-stopped-server)
    $ scw attach $(scw start $(scw create ubuntu-vivid))
  • commit [OPTIONS] SERVER [NAME] The scw commit [OPTIONS] SERVER [NAME] subcommand creates a new snapshot from a server’s volume.
Options:

  -h, --help=false      Print usage
  -v, --volume=0        Volume slot

Examples:

    $ scw commit my-stopped-server
    $ scw commit -v 1 my-stopped-server
  • cp [OPTIONS] SERVER:PATHHOSTPATH- SERVER:PATHHOSTPATH-

The scw cp [OPTIONS] SERVER:PATH|HOSTPATH|- SERVER:PATH|HOSTPATH|- subcommand copies files/folders from a PATH on the server to a HOSTDIR on the host running the command. Use - to write the data as a tar file to STDOUT.

Options:

  -g, --gateway=""      Use a SSH gateway
  -h, --help=false      Print usage
  -p, --port=22         Specify SSH port
  --user=root           Specify SSH user

Examples:

    $ scw cp path/to/my/local/file myserver:path
    $ scw cp --gateway=myotherserver path/to/my/local/file myserver:path
    $ scw cp myserver:path/to/file path/to/my/local/dir
    $ scw cp myserver:path/to/file myserver2:path/to/dir
    $ scw cp myserver:path/to/file - > myserver-pathtofile-backup.tar
    $ scw cp myserver:path/to/file - | tar -tvf -
    $ scw cp path/to/my/local/dir  myserver:path
    $ scw cp myserver:path/to/dir  path/to/my/local/dir
    $ scw cp myserver:path/to/dir  myserver2:path/to/dir
    $ scw cp myserver:path/to/dir  - > myserver-pathtodir-backup.tar
    $ scw cp myserver:path/to/dir  - | tar -tvf -
    $ cat archive.tar | scw cp - myserver:/path
    $ tar -cvf - . | scw cp - myserver:path
  • create [OPTIONS] IMAGE

The create [OPTIONS] IMAGE subcommand creates a new server but does not start it.

Options:

  --bootscript=""           Assign a bootscript
  --commercial-type=X64-2GB Create a server with specific commercial-type C1, C2[S|M|L], X64-[2|4|8|15|30|60|120]GB, ARM64-[2|4|8]GB
  -e, --env=""              Provide metadata tags passed to initrd (i.e., boot=rescue INITRD_DEBUG=1)
  -h, --help=false          Print usage
  --ip-address=dynamic      Assign a reserved public IP, a 'dynamic' one or 'none'
  --name=""                 Assign a name
  --tmp-ssh-key=false       Access your server without uploading your SSH key to your account
  -v, --volume=""           Attach additional volume (i.e., 50G)

Examples:

    $ scw create docker
    $ scw create 10GB
    $ scw create --bootscript=3.2.34 --env="boot=live rescue_image=http://j.mp/scaleway-ubuntu-trusty-tarball" 50GB
    $ scw inspect $(scw create 1GB --bootscript=rescue --volume=50GB)
    $ scw create $(scw tag my-snapshot my-image)
    $ scw create --tmp-ssh-key 10GB
  • events [OPTIONS]

The scw events [OPTIONS] subcommand gets real time events from the API.

  • exec [OPTIONS] SERVER [COMMAND] [ARGS…]

The scw exec [OPTIONS] SERVER [COMMAND] [ARGS...] subcommand launches a command on a running server.

Options:

  -A=false              Enable SSH keys forwarding
  -g, --gateway=""      Use a SSH gateway
  -h, --help=false      Print usage
  -p, --port=22         Specify SSH port
  -T, --timeout=0       Set timeout values to seconds
  --user=root           Specify SSH user
  -w, --wait=false      Wait for SSH to be ready

Examples:

    $ scw exec myserver
    $ scw exec myserver bash
    $ scw exec --gateway=myotherserver myserver bash
    $ scw exec myserver 'tmux a -t joe || tmux new -s joe || bash'
    $ SCW_SECURE_EXEC=1 scw exec myserver bash
    $ scw exec -w $(scw start $(scw create ubuntu-trusty)) bash
    $ scw exec $(scw start -w $(scw create ubuntu-trusty)) bash
    $ scw exec myserver tmux new -d sleep 10
    $ scw exec myserver ls -la | grep password
    $ cat local-file | scw exec myserver 'cat > remote/path'
  • help [COMMAND]

The scw help [COMMAND] subcommand helps print help information about scw and its commands. By default, help lists available commands with a short description. When invoked with a command name, it prints the usage and the help of the command.

  • history [OPTIONS] IMAGE

The scw history [OPTIONS] IMAGE subcommand displays the history of an image.

Options:

  --arch=*              Specify architecture
  -h, --help=false      Print usage
  --no-trunc=false      Don't truncate output
  -q, --quiet=false     Only show numeric IDs
  • images [OPTIONS]

The scw images [OPTIONS] subcommands lists all the images.

Options:

  -a, --all=false       Show all images
  -f, --filter=""       Filter output based on conditions provided
  -h, --help=false      Print usage
  --no-trunc=false      Don't truncate output
  -q, --quiet=false     Only show numeric IDs

Examples:

    $ scw images
    $ scw images -a
    $ scw images -q
    $ scw images --no-trunc
    $ scw images -f organization=me
    $ scw images -f organization=official-distribs
    $ scw images -f organization=official-apps
    $ scw images -f organization=UUIDOFORGANIZATION
    $ scw images -f name=ubuntu
    $ scw images -f type=image
    $ scw images -f type=bootscript
    $ scw images -f type=snapshot
    $ scw images -f type=volume
    $ scw images -f public=true
    $ scw images -f public=false
    $ scw images -f "organization=me type=volume" -qsc
  • info [OPTIONS]

The scw info [OPTIONS] subcommand displays system-wide information.

  • inspect [OPTIONS] IDENTIFIER [IDENTIFIER…]

The scw inspect [OPTIONS] IDENTIFIER [IDENTIFIER...] subcommand returns low-level information on a server, image, snapshot, volume or bootscript.

Options:

  --arch=*              Specify architecture
  -b, --browser=false   Inspect object in browser
  -f, --format=""       Format the output using the given go template
  -h, --help=false      Print usage

Examples:

    $ scw inspect my-server
    $ scw inspect server:my-server
    $ scw inspect --browser my-server
    $ scw inspect a-public-image
    $ scw inspect image:a-public-image
    $ scw inspect my-snapshot
    $ scw inspect snapshot:my-snapshot
    $ scw inspect my-volume
    $ scw inspect volume:my-volume
    $ scw inspect my-image
    $ scw inspect image:my-image
    $ scw inspect my-server | jq '.[0].public_ip.address'
    $ scw inspect $(scw inspect my-image | jq '.[0].root_volume.id')
    $ scw inspect -f "" my-server
    $ scw --sensitive inspect my-server
  • kill [OPTIONS] SERVER

The scw kill [OPTIONS] SERVER kills a running server.

Options:

  -g, --gateway=""      Use a SSH gateway
  -h, --help=false      Print usage
  • login [OPTIONS]

The scw login [OPTIONS] subcommand generates a configuration file in ‘/home/$USER/.scwrc’ containing credentials used to interact with the Scaleway API. This configuration file is automatically used by the ‘scw’ commands. You can get your credentials on https://cloud.scaleway.com/#/credentials

Options:

  -h, --help=false      Print usage
  -o, --organization="" Organization
  -s, --skip-ssh-key=false Don't ask to upload an SSH Key
  -t, --token=""        Token
  • logout [OPTIONS]

The scw logout [OPTIONS] subcommand logs out from Scaleway API.

  • logs [OPTIONS] SERVER

The scw logs [OPTIONS] SERVER subcommand fetches the logs of a server.

Options:

  -g, --gateway=""      Use a SSH gateway
  -h, --help=false      Print usage
  -p, --port=22         Specify SSH port
  --user=root           Specify SSH user
  • port [OPTIONS] SERVER [PRIVATE_PORT[/PROTO]]

The scw port [OPTIONS] SERVER [PRIVATE_PORT[/PROTO]]subcommand lists port mappings for the SERVER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT

Options:

  -g, --gateway=""      Use a SSH gateway
  -h, --help=false      Print usage
  -p, --port=22         Specify SSH port
  --user=root           Specify SSH user
  • products [OPTIONS] PRODUCT

The scw products [OPTIONS] PRODUCT subcommand displays product information.

Options:

  -s, --short           Print only commercial names
  • ps [OPTIONS]

The scw ps [OPTIONS] subcommand lists the running servers.

Options:

  -a, --all=false       Show all servers. Only running servers are shown by default
  -f, --filter=""       Filter output based on conditions provided
  -h, --help=false      Print usage
  -l, --latest=false    Show only the latest created server, include non-running ones
  -n=0                  Show n last created servers, include non-running ones
  --no-trunc=false      Don't truncate output
  -q, --quiet=false     Only display numeric IDs

Examples:

    $ scw ps
    $ scw ps -a
    $ scw ps -l
    $ scw ps -n=10
    $ scw ps -q
    $ scw ps --no-trunc
    $ scw ps -f state=booted
    $ scw ps -f state=running
    $ scw ps -f state=stopped
    $ scw ps -f ip=212.47.229.26
    $ scw ps -f tags=prod
    $ scw ps -f tags=boot=live
    $ scw ps -f image=docker
    $ scw ps -f image=alpine
    $ scw ps -f image=UUIDOFIMAGE
    $ scw ps -f arch=ARCH
    $ scw ps -f server-type=COMMERCIALTYPE
    $ scw ps -f "state=booted image=docker tags=prod"
  • rename [OPTIONS] SERVER NEW_NAME

The scw rename [OPTIONS] SERVER NEW_NAME subcommand renames a server.

  • restart [OPTIONS] SERVER [SERVER…]

The scw restart [OPTIONS] SERVER [SERVER...] subcommand restarts a running server.

Options:

  -h, --help=false      Print usage
  -T, --timeout=0       Set timeout values to seconds
  -w, --wait=false      Synchronous restart. Wait for SSH to be ready
  • rm [OPTIONS] SERVER [SERVER…]

The scw rm [OPTIONS] SERVER [SERVER...] subcommand removes one or more servers.

Options:

  -f, --force=false     Force the removal of a server
  -h, --help=false      Print usage

Examples:

    $ scw rm myserver
    $ scw rm -f myserver
    $ scw rm my-stopped-server my-second-stopped-server
    $ scw rm $(scw ps -q)
    $ scw rm $(scw ps | grep mysql | awk '{print $1}')
  • rmi [OPTIONS] IMAGE [IMAGE…]

The scw rmi [OPTIONS] IDENTIFIER [IDENTIFIER...] subcommand removes one or more image(s)/volume(s)/snapshot(s)

Options:

  -h, --help=false      Print usage

Examples:

    $ scw rmi myimage
    $ scw rmi mysnapshot
    $ scw rmi myvolume
    $ scw rmi $(scw images -q)
  • run [OPTIONS] IMAGE [COMMAND] [ARGS…]

The scw run [OPTIONS] IMAGE [COMMAND] [ARG...] subcommand launches a command in a new server.

Options:

  -a, --attach=false        Attach to serial console
  --bootscript=""           Assign a bootscript
  --commercial-type=X64-2GB Start a server with specific commercial-type C1, C2[S|M|L], X64-[2|4|8|15|30|60|120]GB, ARM64-[2|4|8]GB
  -d, --detach=false        Run server in background and print server ID
  -e, --env=""              Provide metadata tags passed to initrd (i.e., boot=rescue INITRD_DEBUG=1)
  -g, --gateway=""          Use a SSH gateway
  -h, --help=false          Print usage
  --ip-address=""           Assign a reserved public IP, a 'dynamic' one or 'none' (default to 'none' if gateway specified, 'dynamic' otherwise)
  --ipv6=false              Enable IPV6
  --name=""                 Assign a name
  -p, --port=22             Specify SSH port
  --rm=false                Automatically remove the server when it exits
  --show-boot=false         Allows to show the boot
  -T, --timeout=0           Set timeout value to seconds
  --tmp-ssh-key=false       Access your server without uploading your SSH key to your account
  -u, --userdata=""         Start a server with userdata predefined
  --user=root               Specify SSH User
  -v, --volume=""           Attach additional volume (i.e., 50G)

Examples:

    $ scw run ubuntu-trusty
    $ scw run --commercial-type=C2S ubuntu-trusty
    $ scw run --show-boot --commercial-type=C2S ubuntu-trusty
    $ scw run --rm ubuntu-trusty
    $ scw run -a --rm ubuntu-trusty
    $ scw run --gateway=myotherserver ubuntu-trusty
    $ scw run ubuntu-trusty bash
    $ scw run --name=mydocker docker docker run moul/nyancat:armhf
    $ scw run --bootscript=3.2.34 --env="boot=live rescue_image=http://j.mp/scaleway-ubuntu-trusty-tarball" 50GB bash
    $ scw run --attach alpine
    $ scw run --detach alpine
    $ scw run --tmp-ssh-key alpine
    $ scw run --userdata="FOO=BAR FILE=@/tmp/file" alpine
  • search [OPTIONS] TERM

The scw search [OPTIONS] TERM searches the Scaleway Hub for images.

Options:

  -h, --help=false      Print usage
  --no-trunc=false      Don't truncate output
  • start [OPTIONS] SERVER [SERVER…]

The scw start [OPTIONS] SERVER [SERVER...] starts a stopped server.

Options:

  -h, --help=false      Print usage
  -T, --timeout=0       Set timeout values to seconds
  -w, --wait=false      Synchronous start. Wait for SSH to be ready
  • stop [OPTIONS] SERVER [SERVER…]

The scw stop [OPTIONS] SERVER [SERVER...] subcommand stops a running server.

Options:

  -h, --help=false      Print usage
  -t, --terminate=false Stop and trash a server with its volumes
  -w, --wait=false      Synchronous stop. Wait for SSH to be ready

Examples:

    $ scw stop my-running-server my-second-running-server
    $ scw stop -t my-running-server my-second-running-server
    $ scw stop $(scw ps -q)
    $ scw stop $(scw ps | grep mysql | awk '{print $1}')
    $ scw stop server && stop wait server
    $ scw stop -w server
  • tag [OPTIONS] SNAPSHOT NAME

The scw tag [OPTIONS] SNAPSHOT NAME subcommand tags a snapshot into an image.

Options:

  -h, --help=false      Print usage
  --bootscript=""       Assign a bootscript
  • top [OPTIONS] SERVER

The scw top [OPTIONS] SERVER checks the running processes of a server.

Options:

  -g, --gateway=""      Use a SSH gateway
  -h, --help=false      Print usage
  -p, --port=22         Specify SSH port
  --user=root           Specify SSH user
  • version [OPTIONS]

The scw version [OPTIONS] subcommand displays the version information.

  • wait [OPTIONS] SERVER [SERVER…]

The scw wait [OPTIONS] SERVER [SERVER...] subcommand blocks until a server stops.

Use Case: Creating a Farm of nginx Servers Serving Static Content using Scaleway CLI

As an example, we will create a farm of nginx servers serving static content using Scaleway CLI and shell scripting. One front end server will act as a load balancer and proxify requests to nodes serving static content.

1 . Create one server called my-static-farm-front and 4 nodes called my-static-farm-node-$i

FRONTEND_ID=$(scw create --name my-static-farm-front Ubuntu_Bionic)  
for i in {1..5}  
do  
     scw create --name my-static-farm-node-$i Ubuntu_Bionic >> /tmp/farm-uuids.txt
done  

2 . Boot all servers

# start all servers
for server in $(cat /tmp/farm-uuids.txt) $FRONTEND_ID  
do  
      scw start $server &
done  
wait $(jobs -p)

3 . Install nginx

Note: You will be required to enter your passphrase for each server.

install nginx
for server in $(cat /tmp/farm-uuids.txt) $FRONTEND_ID  
do
      scw exec $server 'apt-get update && apt-get install -q -y nginx'
done  

# add a dummy static content on nodes
for server in $(cat /tmp/farm-uuids.txt) $FRONTEND_ID  
do  
      scw exec $server 'echo HelloWorld > /usr/share/nginx/html/index.html'
done

4 . Configure the frontend to act as a load balancer. We’ll need to fetch the IP addresses of our new servers:

(
    echo "upstream static-nodes {"
    for server in $(cat /tmp/farm-uuids.txt)
    do
        ip=$(scw inspect $server -f '.server.public_ip.address')
        echo "    server ${ip};"
    done
    echo "}"
    echo "server {"
    echo "        listen 80;"
    echo "        location / {"
    echo "                proxy_pass http://static-nodes;"
    echo "        }"
    echo "}"
) | scw exec $FRONTEND_ID 'cat > /etc/nginx/sites-enabled/default'

scw exec $FRONTEND_ID 'service nginx reload'  

5 . The frontend is available at

echo "http://$(scw inspect $FRONTEND_ID -f '.server.public_ip.address')"  

Find out more example on our github repository or more advanced examples here

Scaleway API Golang Client

Scaleway API Go client contains facilities to play with the Scaleway API, it includes the following features:

  • dedicated configuration file containing credentials to deal with the API
  • caching to resolve UUIDs without contacting the API

Discover a New Cloud Experience

Deploy SSD Cloud Servers in seconds.