Skip to navigationSkip to main contentSkip to footerScaleway Docs HomepageAsk our AI
Ask our AI

How to automate the management of your resources using Serverless Jobs

Scaleway Serverless Jobs allows you to create and automate recurring tasks. This page shows how to create jobs to perform any operation available with the Scaleway CLI (External link) to automate the management of your Scaleway resources.

Note

To automate complex commands, such as piped or xargs commands, refer to the dedicated documentation.

Serverless Jobs are perfectly adapted for these autonomous tasks, as we do not need autoscaling or exposure via a web server. Refer to the documentation on differences between jobs, containers, and functions for more information.

Before you start

To complete the following actions, you must have:

Creating the job definition

  1. In the Scaleway console (External link), click Jobs in the Serverless section of the side menu. The jobs page displays.

  2. Click Create job. The job creation wizard displays.

  3. For Container Image, select External, and in Image URL, set: scaleway/cli:latest.

  4. Enter a name or use the automatically generated one.

  5. Select the region in which your job will be created.

  6. Keep the default resources values, as this job requires little compute capability.

  7. Set a cron schedule in the * * * * * format (such as 0 0 * * * to run the job every day at midnight), and select the relevant time zone to run the job at the desired frequency. Refer to the cron schedules documentation for more information.

  8. Define the following environment variables:

    • SCW_ACCESS_KEY: your API access key.
    • SCW_SECRET_KEY: your API secret key.
    • SCW_DEFAULT_PROJECT_ID: your Project ID.
    • SCW_DEFAULT_ORGANIZATION_ID: your Organization ID.
    • SCW_DEFAULT_REGION: desired region.
    • SCW_INSTANCE_ID: Instance ID to start/stop.
    Note

    We recommend using Secret Manager to store the SCW_ACCESS_KEY and SCW_SECRET_KEY.

    For more details about variables used by cli, refer to the CLI config documentation (External link).

  9. In the Execution tab, define the desired Scaleway CLI arguments, as shown in the examples below:

    • Power Instances on and off
      # Power on
      "instance" "server" "start" "$(SCW_INSTANCE_ID)"
      
      # Power off
      "instance" "server" "stop" "$(SCW_INSTANCE_ID)"
    • Create a snapshot of an Instance volume
      instance snapshot create volume-id=11111111-1111-1111-1111-111111111111
    • Create a backup of an Instance
      instance server backup 11111111-1111-1111-1111-111111111111
  10. Click Create job.

Your Serverless Job will run the command periodically according to the cron schedule you defined.

Running the job

From the Overview tab of the Serverless Job you just created, click Actions, then select Run job from the contextual menu.

The execution appears in the Job runs section. To view its logs, click more icon next to the job run ID, then select See on Cockpit.

Still need help?

Create a support ticket
No Results