This project shows how it's possible to automate tasks using Serverless Jobs.
This example is very simple, it generates snapshots of your desired Instance.
- Scaleway Account
- Docker daemon running to build the image
- Container registry namespace created, for this example we assume that your namespace name is
jobs-snapshot
: doc here - API keys generated, Access Key and Secret Key doc here
Serverless Jobs, like Serverless Containers (which are suited for HTTP applications), works with containers. So first, use your terminal reach this folder and run the following commands:
# First command is to login to container registry, you can find it in Scaleway console
docker login rg.fr-par.scw.cloud/jobs-snapshot -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
# Here we build the image to push
docker build -t rg.fr-par.scw.cloud/jobs-snapshot/jobs-snapshot:v1 .
## TIP: for Apple Silicon or other ARM processors, please use the following command as Serverless Jobs supports amd64 architecture
# docker buildx build --platform linux/amd64 -t rg.fr-par.scw.cloud/jobs-snapshot/jobs-snapshot:v1 .
# Push the image online to be used on Serverless Jobs
docker push rg.fr-par.scw.cloud/jobs-snapshot/jobs-snapshot:v1
Tip
As we do not expose a web server and we do not require features such as auto-scaling, Serverless Jobs are perfect for this use case.
To check if everyting is ok, on the Scaleway Console you can verify if your tag is present in Container Registry.
On Scaleway Console on the following link you can create a new Job Definition: https://console.scaleway.com/serverless-jobs/jobs/create?region=fr-par
- On Container image, select the image you created in the step before.
- You can set the image name to something clear like
jobs-snapshot
too. - For the region you can select the one you prefer :)
- Regarding the resources you can keep the default values, this job is fast and do not require specific compute power or memory.
- To schedule your job for example every night at 2am, you can set the cron to
0 2 * * *
. - Important: advanced option, you need to set the following environment variables:
Tip
For sensitive data like SCW_ACCESS_KEY
and SCW_SECRET_KEY
we recommend to inject them via Secret Manager, more info here.
INSTANCE_ID
: grab the instance ID you want to create snapshots fromINSTANCE_ZONE
: you need to give the ZONE of you instance, likefr-par-2
SCW_ACCESS_KEY
: your access keySCW_SECRET_KEY
: your secret keySCW_DEFAULT_ORGANIZATION_ID
: your organzation ID
- Then click "create job"
On your created Job Definition, just click the button "Run Job" and within seconds it should be successful.
If your Job Run state goes in error, you can use the "Logs" tab in Scaleway Console to get more informations about the error.
You can exercice by adding the following features:
- Instead of managing a single instance, make it account wide
- Add disk backups
- Add alerts if something goes wrong
- Use secret manager instead of job environment variables