Skip to content

docs(srv): how to automate scw resource mgmt w/ jobs MTA-6074 #5115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions menu/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,10 @@
"label": "Build and push a container image",
"slug": "build-push-container-image"
},
{
"label": "Automate resources management with Jobs",
"slug": "automate-resources-management"
},
{
"label": "Manage the scheduling of a job",
"slug": "manage-job-schedule"
Expand Down
6 changes: 5 additions & 1 deletion pages/scaleway-cli/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@ Refer to the [Scaleway CLI repository](https://github.com/scaleway/scaleway-cli)

<Message type="note">
Refer the the [Scaleway CLI repository](https://github.com/scaleway/scaleway-cli?tab=readme-ov-file#reference-documentation) for more information on the different commands.
</Message>
</Message>

## Going Further

You can periodically execute CLI commands with Serverless Jobs to automate the management of your Scaleway resources. Refer to the [dedicated documentation](/serverless-jobs/how-to/automate-resources-management/) for more information.
79 changes: 79 additions & 0 deletions pages/serverless-jobs/how-to/automate-resources-management.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
meta:
title: How to automate the management of your resources using Serverless Jobs
description: This step-by-step guide will help you automate the management of your resources using Serverless Jobs and the Scaleway CLI
content:
h1: How to automate the management of your resources using Serverless Jobs
paragraph: This step-by-step guide will help you automate the management of your resources using Serverless Jobs and the Scaleway CLI
tags: serverless jobs command line interface cli automate resources management
categories:
- developer-tools
- jobs
dates:
validation: 2025-06-13
posted: 2025-06-13
---
[Scaleway Serverless Jobs](/serverless-jobs/quickstart/) allows you to create and automate recurring tasks. This page shows how to create jobs to perform any operation available with the [Scaleway CLI](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/config.md) to automate the management of your Scaleway resources.

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](/serverless-jobs/reference-content/difference-jobs-functions-containers/) for more information.

<Macro id="requirements" />

- A Scaleway account logged into the [console](https://console.scaleway.com).
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization.

## Creating the job definition

1. In the [Scaleway console](https://console.scaleway.com), 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](/serverless-jobs/reference-content/cron-schedules/) 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.

<Message type="note">
We recommend using [Secret Manager](/secret-manager/quickstart/) to store the `SCW_ACCESS_KEY` and `SCW_SECRET_KEY`.
</Message>

For more details about variables used by `cli`, refer to the [CLI config documentation](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/config.md).

9. In the **Execution** tab, define the desired Scaleway CLI command, as shown in the examples below:
- **Power on and off Instances**
```sh
# Power on
scw instance server start 11111111-1111-1111-1111-111111111111

# Power off
scw instance server stop 11111111-1111-1111-1111-111111111111
```
- **Create a snapshot of an Instance volume**
```sh
scw instance snapshot create volume-id=11111111-1111-1111-1111-111111111111
```
- **Create a backup of an Instance**
```sh
scw 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](/serverless-jobs/reference-content/cron-schedules/) 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. You can access the logs of your job by clicking <Icon name="more" /> next to the job run ID, and selecting **See on Cockpit**.