Blueprints

Manage Aiven resources from the CLI — start and stop services or databases on schedule

About this blueprint

CLI Trigger Python

This flow shows how to manage Aiven resources from the CLI. It assumes that you have an Aiven account and that you created an API token. Make sure to replace the AVN_AUTH_TOKEN value in the task with your Aiven API token. It's recommended to use Secrets to store sensitive data such as API tokens.

Once you've configured the Aiven secret, you can reproduce this flow without any changes.

The first command is great to test the setup — the command will just list your Aiven projects. However, there is a lot more you can do with the Aiven CLI. Check out the Aiven CLI guide for more information.

For example, you can use it to start and stop specific services in your Aiven projects using scheduled flows in Kestra. This is useful if you want to save money by stopping your services when you don't need them, e.g. at night or during the weekend.

You can also use the CLI to create and delete services or databases on demand.

yaml
id: aiven
namespace: company.team
tasks:
  - id: cli
    type: io.kestra.plugin.scripts.python.Commands
    warningOnStdErr: false
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
    containerImage: python:slim
    beforeCommands:
      - pip install aiven-client
    commands:
      - avn --auth-token $AVN_AUTH_TOKEN project list
      - avn --auth-token $AVN_AUTH_TOKEN service update YOUR-SERVICE-NAME
        --power-off
      - avn --auth-token $AVN_AUTH_TOKEN service update YOUR-SERVICE-NAME
        --power-on
    env:
      AVN_AUTH_TOKEN: "{{ secret('AVN_AUTH_TOKEN') }}"
triggers:
  - id: every_morning
    type: io.kestra.plugin.core.trigger.Schedule
    cron: 0 9 * * *

Commands

Docker

Schedule

New to Kestra?

Use blueprints to kickstart your first workflows.

Get started with Kestra