Skip to content

Aiven Logo
  • Pricing
  • Blog

Log in

Book a demo

Start for free

Developer Center
  1. Aiven Developer Center
  2. Databases

Get things done with the Aiven CLI

There's more than one way to use Aiven. Read on to learn how to use the Aiven command line tool to do common tasks.

  • Tutorial
  • PostgreSQL®
Subscribe to RSS
Loading...

Subscribe to RSS

The Aiven command line

GUIs (Graphical User Interfaces) like the Aiven web
console
are a very approachable way to interact with systems,
especially since they can guide you towards the actions you might want to do.
When it comes to repeatability and automation however, these interfaces have limitations.

Luckily, almost every action available in the web console is also possible
using the open source avn CLI tool,
aiven-client. This tool is also heavily used
within Aiven itself, which means that it is well supported and gains new
service management features regularly.

In this article I will lead you through some common operations, using a
PosgreSQL® service as an example.

Install avn

Following the instructions at Aiven CLI: Getting
started
, install the Aiven
CLI tool with pip:

Loading code...

A fun way to check that the command is working is with this special feature:

Loading code...

This will give you a nice piece of ASCII art.

Get help with the avn command

You can get help from avn in a few different ways.

To get general help on how to use the command, including a summary of the switches
the command accepts, and a list of the top-level subcommands:

Loading code...

You can also get help on specific commands by adding --help to the end of
the command line. For example to get some help with how to use the avn user login command:

Loading code...

You can get a (long) list of all the avn commands and a brief note of what
they each do by using:

Loading code...

This can be useful if you're trying to "guess" what command to use.

For instance, here's a part of the output relating to PostgreSQL®,
showing us the commands to retrieve the service connection information
as a string, as a URI, or in the format that psql needs:

Loading code...

Get an account

If you've already got an Aiven account, then you're ready to go.

Otherwise, you can sign up at the Aiven console - either for a free plan or for a free trial.

Log in to Aiven with avn

Most avn commands require authentication.
At the command line, this is normally done by logging in with an
authentication token.

Using a token rather than username and password is considered good practice.
Tokens can be limited to a specific time period, and they can also
be revoked, removing access only for those using that token, without affecting
other use cases. Resetting a password would have a much wider impact.

By default, logging in to Aiven with a password is not enabled. See Enable Aiven password if you really need it.

Get an authentication token, as described at Create an authentication
token
,
copy it, and log in using the following command. You'll need to replace
YOUR-EMAIL-ADDRESS with the email address you've registered with Aiven.

Loading code...

This will prompt you to paste in your token, and then report that it has
saved your credentials to a JSON file on your filesystem.

An alternative to logging in is to specify the authentication token with each command. This approach can be useful in a script, where you would set an environment variable (for instance, AVN_AUTH_TOKEN) to the token, and then write each command as avn --auth-token $AVN_AUTH_TOKEN ...

Choose a project

Aiven uses "projects" to organise which services you can access. You can get a
list of the projects that you have access to, their default clouds, and some
information on payments with a command like this:

Loading code...

For instance, as a Developer Educator at Aiven, I see output something like the following:

Loading code...

Once you know which project you're going to be using, you can select it, replacing
PROJECT-NAME with the name of the actual project:

Loading code...

This makes that the default project for future commands.

Commands will generally also take a --project switch if you want to use a project without selecting it.

Find out about a project

To find out more about a project:

Loading code...

This will typically show the default cloud for the project, its billing
currency, and maybe details of the VAT ID being used, the billing address and
credit card data (if appropriate).

Loading code...

Get JSON data

Commands that return data also take a --json switch, which causes them to
return their data in JSON. This often includes more information than is
provided by the standard text output. For instance altering our earlier command to include the switch:

Loading code...

This version gives a lot more detail, including account name and id, available credits and
current estimated balance.

Sometimes the data produced with --json can be overwhelming, especially if
you're only looking for one particular field. In that case, it can be useful
to pipe the JSON output into the jq tool,
and use a query to select just the information you want.

For instance, to find the name of the default cloud for the current project, do:

Loading code...

The command returns just the name of the cloud.

Find out what services are available

You can find out what services (PostgreSQL®, Apache Kafka®, OpenSearch®, etc.)
are available for the current project with this command:

Loading code...

This will will list the services and the abbreviation used for each service
type.

For instance, the entry for PostgreSQL looks like this:

Loading code...

Since PostgreSQL is such an excellent database, we're going to create a pg service and show off some more avn commands.

Find a cloud

In order to create a new service, you need to decide what region you want it
to run in, and what capabilities you need. To find out what clouds and regions
are available:

Loading code...

This will show the available clouds and information about them - specifically,
a description of the cloud, its name, its location (as latitude and longitude)
and its region.

The output will be lines looking something like:

Loading code...

Using the --json switch and jq can help if you want to get more
details of just part of the information. For instance, to find the information
for all the services in europe, try this:

Loading code...

You should see a list of entries like the one below:

Loading code...

To get just that particular entry, you could use:

Loading code...

Find a service plan

Aiven uses "service plans" to define the number of servers and what kind of
memory, CPU, and disk resources are allocated to your service.

To get a list of the available service plans for PostgreSQL in the cloud
google-europe-north1, including the plan name, its cost and what resources
it provides, use this command:

Loading code...

Here's part of the output I get:

Loading code...

It's worth trying different clouds to see how pricing differs between them.

The price quoted is all inclusive (although some services also allow the purchase of extra storage space).

Create a PostgreSQL® service

For this first service creation, create a PostgreSQL service on the Finnish
Google cloud at the Hobbyist level.

It's important to give the service a unique name - I like to put my own
name into it, but you should use your own! Beware that the name can't be
changed after you've created the service.

Loading code...

The command will return immediately. Meanwhile, Aiven will start creating the service, which will take a little while to build.

If your target cloud includes VPCs (virtual private clouds) then it is safest to be explicit whether you want to create the new service in the VPC or not. See avn vpc list if you're not sure if your project has VPCs, and avn service create for the VPC related switches, specifically --no-project-vpc and --project-vpc-id PROJECT_VPC_ID

If you want to wait for the service to start, you can use the wait command for the service:

Loading code...

This will report the progress of the newly-created service as it comes up.

Loading code...

The command will return when the service is RUNNING (the ... means there might be multiple "Waiting" messages).
The wait command is especially useful in a script, when you have another command to run when things are ready.

You can explicitly check the state of the service, as well as other
information:

Loading code...

This returns service information like this:

Loading code...

If you just want the current state of the service, use --json and jq as we did earlier to
get the field you want from the output:

Loading code...

Interact with the PostgreSQL service

Once the PostgreSQL service is running, we can use the command line to
interact with it.

To find out what databases are present:

Loading code...

This will just show the default database since we just created a new service:

Loading code...

We can create a new database using avn:

Loading code...

If you list the databases again, the new one will appear:

Loading code...

Since this is a PostgreSQL database, we could get the connection details from avn
and use them to connect to the
database:

Loading code...

But it's probably easier to use the built-in helper:

Loading code...

This will run the appropriate CLI for the service - for our PostgreSQL service, that means psql.

Finally for this section, I like to know the backup status of services I'm
using. I can get a list of when backups were made and what region they're
stored in with:

Loading code...
Backup handling differs from service to service and from plan to plan. See Backups at Aiven for an overview, and PostgreSQL® backups if you just want the PostgreSQL specifics.

Change plan, cloud and region

We created our PostgreSQL service using the Hobbyist plan. That's fine for
trying out a service, but it's definitely not suitable for production
use.

The avn service update command allows us to change the details of our service.

To update to a Startup-8 plan running on AWS in Ireland (aws-eu-west-1):

Loading code...

This will take a little while, because it has to start a new service with a
copy of the original data. How long it takes will depend on the amount of
data, and how busy the systems are. As before, you can use avn service get
or avn service wait to tell when it has finished. See the documentation for
Migrate
services
and
Scale your
service
. (Aiven takes care that there is no service interruption during a change like
this).

Once the service is RUNNING again, check the new plan and location:

Loading code...

Keep things tidy

If you're not going to be using a service for a while, then powering it off
will stop you being charged for it:

Loading code...

The command won't return until the service is powered off.

Some services that have "event-like" state, such as Apache Kafka® and Apache Flink®, will lose that state when they are powered off.

You can power the service back on again by using the update command once more:

Loading code...

Remember it will take a while before the service returns to the RUNNING state.

If you no longer need the service, then delete it:

Loading code...

Since this will delete the service and all associated data, it prompts you to
type in the service name to confirm the operation.

Further reading

We barely scratched the surface of the available features in this tool. For more information, visit the Aiven documentation
where you will find a whole section on the Aiven CLI.

The README for
the Aiven Client GitHub repository
also contains useful information and examples.

There's also an Introduction to Aiven CLI video, which covers some of the same material.

And for an example of using the Aiven CLI in a Bash script, see
Controlling non-production Aiven Services with the CLI

Alternatively, try one of the other ways to work with the Aiven platform:

  • the Aiven web console
  • the Aiven API - this is what
    the command line tool and the web console use to communicate with the Aiven platform
  • Terraform and the Aiven Terraform provider
  • Kubernetes® and Aiven Operator for Kubernetes

Table of contents

  • The Aiven command line
  • Install avn
  • Get help with the avn command
  • Get an account
  • Log in to Aiven with avn
  • Choose a project
  • Find out about a project
  • Get JSON data
  • Find out what services are available
  • Find a cloud
  • Find a service plan
  • Create a PostgreSQL® service
  • Interact with the PostgreSQL service
  • Change plan, cloud and region
  • Keep things tidy
  • Further reading
Aiven Logo at footer
Loading...
  • Github
  • Facebook
  • LinkedIn
  • Twitter
  • Youtube

Company

  • About
  • Open source
  • Careers
  • Sustainability
  • Modern slavery statement
  • Press
  • Blog

Legal

  • Terms
  • SLA
  • AUP
  • Data processing
  • Privacy
  • DSA contact
  • Cookie policy
  • Website terms of use
  • Do not sell or share my personal information

Platform

  • Responsibility matrix
  • Subprocessors
  • Security and compliance
  • Resource library
  • Support services
  • Changelog
  • Aiven status

Contact

  • Contact us
  • Book a demo
  • Support
  • Invoice address
  • Events calendar

Copyright © Aiven 2016-2025. Apache, Apache Kafka, Kafka, Apache Flink, and Flink are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. ClickHouse is a registered trademark of ClickHouse, Inc. https://clickhouse.com. OpenSearch, PostgreSQL, MySQL, Grafana, Dragonfly, Valkey, Thanos, Terraform, and Kubernetes are trademarks and property of their respective owners. All product and service names used in this website are for identification purposes only and do not imply endorsement.

pip install aiven-client
avn crab
avn --help
avn user login --help
avn help
service connection-info pg string PostgreSQL connection string service connection-info pg uri PostgreSQL service URI service connection-info psql psql command string
avn user login YOUR-EMAIL-ADDRESS --token
avn project list
PROJECT_NAME DEFAULT_CLOUD CREDIT_CARD ============= =================== =========== dev-advocates google-europe-west3 N/A
avn project switch PROJECT-NAME
avn project details
PROJECT_NAME DEFAULT_CLOUD BILLING_CURRENCY VAT_ID ============= ================ ================ ========== dev-advocates aws-eu-west-1 EUR FIxxxxxxxx credit_card = N/A billing_address = "Some address, somewhere" country_code = FI
avn project details --json
avn project details --json | jq '.[] | .default_cloud'
avn service types
pg PostgreSQL - Object-Relational Database Management System
avn cloud list
Europe, Belgium - Google Cloud: Belgium google-europe-west1 50.45 3.82 europe
avn cloud list --json | jq '.[] | select(.geo_region=="europe")'
{ "cloud_description": "Europe, Finland - Google Cloud: Finland", "cloud_name": "google-europe-north1", "geo_latitude": 60.5693, "geo_longitude": 27.1878, "geo_region": "europe" }
avn cloud list --json | jq '.[] | select(.cloud_name=="google-europe-north1")'
avn service plans --service-type pg --cloud google-europe-north1
PostgreSQL - Object-Relational Database Management System Plans pg:hobbyist $0.026/h Hobbyist (1 CPU, 2 GB RAM, 8 GB disk) pg:startup-4 $0.103/h Startup-4 (1 CPU, 4 GB RAM, 80-240 GB disk) pg:startup-8 $0.205/h Startup-8 (2 CPU, 8 GB RAM, 175-525 GB disk)
avn service create YOUR-NAME-demo-pg --service-type pg \ --cloud google-europe-north1 --plan hobbyist
avn service wait YOUR-NAME-demo-pg
INFO Service 'YOUR-NAME-demo-pg' state is now 'REBUILDING' INFO Waiting for services to start ... INFO Waiting for services to start INFO Service 'YOUR-NAME-demo-pg' state is now 'RUNNING' INFO Service(s) RUNNING: YOUR-NAME-demo-pg
avn service get YOUR-NAME-demo-pg
SERVICE_NAME SERVICE_TYPE STATE CLOUD_NAME PLAN CREATE_TIME UPDATE_TIME NOTIFICATIONS ================= ============ ========== ==================== ======== ==================== ==================== ============= YOUR-NAME-demo-pg pg REBUILDING google-europe-north1 hobbyist 2022-05-25T12:18:02Z 2022-05-25T12:18:43Z
avn service get YOUR-NAME-demo-pg --json | jq .state
avn service database-list YOUR-NAME-demo-pg
defaultdb
avn service database-create YOUR-NAME-demo-pg --dbname database2
database2 defaultdb
avn service get YOUR-NAME-demo-pg --json | jq .service_uri_params
avn service cli YOUR-NAME-demo-pg
avn service backup-list YOUR-NAME-demo-pg
avn service update YOUR-NAME-demo-pg --plan startup-8 --cloud aws-eu-west-1
avn service get YOUR-NAME-demo-pg
avn service update YOUR-NAME-demo-pg --power-off
avn service update YOUR-NAME-demo-pg --power-on
avn service terminate YOUR-NAME-demo-pg