Commands icon
Docker icon
Schedule icon

Manage Aiven resources from the CLI, start and stop services on schedule

Run the Aiven CLI on a schedule with Kestra to power services and databases off at night and on in the morning, cutting Aiven cloud costs automatically.

Categories
CoreInfrastructure
id: manage-aiven-resources-from-cli
namespace: company.team

tasks:
  - id: cli
    type: io.kestra.plugin.scripts.python.Commands
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
    containerImage: python:slim
    dependencies:
      - 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 * * *

Run the Aiven command line client (avn) on a schedule with Kestra to manage your Aiven cloud services and databases as code. This blueprint lists your Aiven projects to confirm authentication, then powers a managed service off and back on, so idle PostgreSQL, Kafka, OpenSearch, Redis, or ClickHouse services stop billing overnight or on weekends and resume before your team needs them. It is the cost-optimization automation Aiven's console alone cannot run unattended.

How it works

  • A single cli task of type io.kestra.plugin.scripts.python.Commands runs on a python:slim container through the io.kestra.plugin.scripts.runner.docker.Docker task runner.
  • The task declares the aiven-client pip dependency, so the avn binary is installed at runtime with no custom image to maintain.
  • Three avn commands run in sequence: project list to validate the token, then service update YOUR-SERVICE-NAME --power-off and service update YOUR-SERVICE-NAME --power-on.
  • The AVN_AUTH_TOKEN environment variable is populated from {{ secret('AVN_AUTH_TOKEN') }} and passed to every command, so the token never appears in plaintext.
  • An io.kestra.plugin.core.trigger.Schedule trigger named every_morning fires the flow daily at 0 9 * * *.

What you get

  • Hands-off start and stop of Aiven services on a cron schedule.
  • Lower Aiven bills by powering down non-production services outside working hours.
  • A reproducible, version-controlled definition of how your Aiven estate is managed.
  • Secret-based authentication with no hardcoded tokens.

Who it's for

  • Platform and DevOps engineers managing Aiven services across environments.
  • Data engineers who want dev and staging databases stopped overnight.
  • FinOps owners chasing predictable, reduced cloud spend.

Why orchestrate this with Kestra

Aiven's own console has no built-in scheduler to power services off and on around your team's hours. Kestra adds a declarative YAML Schedule trigger, automatic retries on transient CLI failures, full execution logs and lineage for every power cycle, and the ability to chain Aiven actions with the rest of your pipeline (for example, run a backup before power-off). You manage the whole lifecycle as code instead of clicking through a dashboard.

Prerequisites

  • An Aiven account with at least one service you can power off and on.
  • Docker available to the Kestra worker for the task runner.

Secrets

  • AVN_AUTH_TOKEN: an Aiven authentication token with permission to list projects and update services.

Quick start

  1. Create the AVN_AUTH_TOKEN secret in your Kestra instance.
  2. Replace YOUR-SERVICE-NAME in the --power-off and --power-on commands with your real Aiven service name.
  3. Run the flow once to confirm project list succeeds.
  4. Adjust the every_morning cron to match your desired schedule and enable the trigger.

How to extend

  • Add a second scheduled flow (or a second trigger) to power services off in the evening and on in the morning.
  • Swap service update for service create, service terminate, or service database-create to provision or tear down resources on demand.
  • Parameterize the service name with flow inputs to reuse the same flow across many services.
  • Pull service names from a list and loop with io.kestra.plugin.core.flow.ForEach to manage a whole fleet.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.