-
Notifications
You must be signed in to change notification settings - Fork 260
docs(srv): Jobs x Instances power cycle tuto MTA-6097 #5091
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| --- | ||
| meta: | ||
| title: Power on and off your Instance with Serverless Jobs and the Scaleway CLI | ||
| description: This step-by-step tutorial will help you automate the startup and shutdown of your Instance using Serverless Jobs and the Scaleway CLI | ||
| content: | ||
| h1: Power on and off your Instance with Serverless Jobs and the Scaleway CLI | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| paragraph: This step-by-step tutorial will help you automate the startup and shutdown of your Instance using Serverless Jobs and the Scaleway CLI | ||
| tags: serverless jobs instance cli turn on off power start stop reboot | ||
| categories: | ||
| - instances | ||
| - jobs | ||
| dates: | ||
| validation: 2025-06-09 | ||
| posted: 2025-06-09 | ||
| --- | ||
| [Scaleway Serverless Jobs](/serverless-jobs/quickstart/) allows you to create and automate recurring tasks. This tutorial will guide you through the process of powering on and off a [Scaleway Instance](/instances/quickstart/) on a recurring schedule using a Serverless Job. | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
| - Created an [Instance](/instances/how-to/create-an-instance/). | ||
|
|
||
| ## Creating the job definitions | ||
|
|
||
| ### Serverless Job to power on the Instance | ||
|
|
||
| 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 **cron schedule** to `0 9 * * 1-5` and select the relevant time zone to run the job every morning at 9:00 a.m (09:00) from Monday through Friday. 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`: concerned region. | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Message type="note"> | ||
| We recommend using Secret Manager 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://cli.scaleway.com/instance/#power-on-server). | ||
|
|
||
| 9. In the **Execution** tab, enter the command below, and replace the placeholder with your Instance ID: | ||
|
|
||
| ``` | ||
| scw instance server start 11111111-1111-1111-1111-111111111111 | ||
| ``` | ||
|
|
||
| 10. Click **Create job**. | ||
|
|
||
| ### Serverless Job to power off the Instance | ||
|
|
||
| 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 **cron schedule** to `0 18 * * 1-5` and select the relevant time zone to run the job every evening at 6:00 p.m (18:00) from Monday through Friday. 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`: concerned region. | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <Message type="note"> | ||
| We recommend using Secret Manager 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://cli.scaleway.com/instance/#power-on-server). | ||
|
|
||
| 9. In the **Execution** tab, enter the command below, and replace the placeholder with your Instance ID: | ||
|
|
||
| ``` | ||
| scw instance server stop 11111111-1111-1111-1111-111111111111 | ||
| ``` | ||
|
|
||
| 10. Click **Create job**. | ||
|
|
||
| ## Testing the jobs | ||
|
|
||
| According to the current state of your Instance, Run either the **Power on** or **Power off** job first. | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| From the **Overview** tab of each 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 jobs by clicking <Icon name="more" /> next to the job run ID, and selecting **See on Cockpit**. | ||
|
|
||
| ## Possible improvements | ||
|
|
||
| This tutorial is a lightweight example of how to manage the power cycle of an Instance. You can go further by: | ||
| - Using it to manage all your Instances' power cycles | ||
| - Using Jobs to create [snapshots of your Instances](/tutorials/snapshot-instances-jobs/) | ||
| - Setting up an alerting system in case of unexpected behavior | ||
| - Explore [scaleway/serverless-examples repository](https://github.com/scaleway/serverless-examples) for advanced automation examples | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Additional resources | ||
|
|
||
| - [Serverless Jobs Documentation](/serverless-jobs/how-to/create-job/) | ||
| - [Other methods to deploy Jobs](/serverless-jobs/reference-content/deploy-job/) | ||
| - [API keys documentation](/iam/how-to/create-api-keys/) | ||
| - [CRON schedule reference](/serverless-jobs/reference-content/cron-schedules/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.