AWS Big Data Blog

Export and import Kibana dashboards with Amazon ES

September 8, 2021: Amazon Elasticsearch Service has been renamed to Amazon OpenSearch Service. See details.


Kibana is a popular open-source visualization tool designed to work with Elasticsearch. Amazon OpenSearch Service provides an installation of Kibana with every Amazon OpenSearch Service domain. Users of Kibana can create visualizations and add them into a dashboard. As organizations invest time and resources into creating these dashboards, the need arises to reuse these dashboards within additional Amazon OpenSearch Service domains or even in additional AWS accounts. In this post, we walk through the methods to export an existing Kibana dashboard and import that dashboard into an additional Amazon OpenSearch Service domain.

The following examples use Amazon OpenSearch Service version 7.9, with fine-grained access control enabled. If you’re using a different version of Amazon OpenSearch Service, menu names or the location of functions in the UI are slightly different.

Prerequisites

Before getting started, make sure you have the following prerequisites:

  1. Amazon OpenSearch Service domain version 7.9
  2. Fine-grained access control enabled. To learn how to set this up, see our documentation
  3. The username and password of a user that has been added to the kibana_user role

Dashboard export

You can export a Kibana dashboard two different ways:

  • Kibana UI – With the web-based UI, you can export existing dashboards easily with no coding or API experience required
  • Kibana API – With the available Kibana API endpoints, developers and administrators can script or automate the process of exporting dashboards

Kibana UI

The Kibana UI provides the ability to export dashboards directly through the web browser. To export, perform the following steps:

  1. Log in to the Kibana dashboard.
  2. In the navigation pane, choose Stack Management.
  3. Choose Saved Objects.
  4. On the search page for saved objects, choose the Type drop-down menu and choose dashboard.This lists the available dashboards for export.
  1. Select one or more available dashboards and choose Export.
  2. Make sure Include related objects is enabled (should be enabled by default).This step also exports all visualizations that are contained in the dashboard.
  1. Choose Export.

This process produces an NDJSON file that you can import into another Amazon OpenSearch Service Kibana instance. We discuss the import process later in this post.

Kibana API

Kibana also provides the ability to export dashboards via an API endpoint. You can integrate this method with operational scripts, applications, or any other mechanism that can submit an HTTP POST command. To export a specific dashboard, you must know the ID of that dashboard. You can find the ID in the URL of the dashboard. When viewing the dashboard within Kibana, the URL contains the dashboard ID as shown here:

https://{domain-endpoint}/_plugin/kibana/app/dashboards#/view/{dashboard ID}?...

The dashboard ID is in a format similar to edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b.

Now that you know the dashboard ID, you can export the same NDJSON file that the UI generated by issuing the following HTTP POST command:

curl -X POST https://{domain_endpoint}/_plugin/kibana/auth/login -H "kbn-xsrf: true" -H "content-type:application/json" -d '{"username":"{username}", "password" : "{password}"} ' -c auth.txt

This produces the appropriate authorization cookies to use for the next command. The file auth.txt holds these authorization cookie values.

curl -XGET -H "kbn-xsrf:true" -b auth.txt https://{domain_endpoint}/_plugin/kibana/api/kibana/dashboards/export?dashboard={dashboard ID} > dashboard.ndjson

The same NDJSON artifact is now located in the dashboard.ndjson file that was exported using the Kibana UI.

Dashboard import

You can import a dashboard into Kibana using the same two methods as dashboard exporting: through the Kibana UI via a web browser, or by using the Kibana API directly. See the following code:

Kibana UI

The Kibana UI provides the ability to import dashboards directly through the web browser. To import, perform the following steps:

  1. Log in to the Kibana dashboard.
  2. In the navigation pane, choose Stack Management.
  3. Choose Saved Objects.
  4. On the search page for saved objects, choose Import.
  5. Select the appropriate file.
  6. Optionally, select Automatically overwrite all saved objects.
  7. Choose Import.

Kibana API

Kibana also provides the ability to import dashboards via an API endpoint. You can integrate this method with operational scripts, applications, or any other mechanism that can submit an HTTP POST command. To import a previously exported NDJSON file, issue the following HTTP POST command:

curl -X POST https://{domain_endpoint}/_plugin/kibana/auth/login -H "kbn-xsrf: true" -H "content-type:application/json" -d '{"username":"{username}", "password" : "{password}"} ' -c auth.txt

This produces the appropriate authorization cookies to use for the next command. The file auth.txt holds these authorization cookie values.

The following code imports all objects defined in the NDJSON file and is immediately available in the Kibana UI:

curl -XPOST https://{domain_endpoint}/_plugin/kibana/api/saved_objects/_import -H "kbn-xsrf:true" -b auth.txt --form file=@dashboard.ndjson

Conclusion

In this post, you learned how to use Kibana’s import and export dashboard feature using the browser-based UI as well as through the API. You can use this feature to copy dashboards and visualizations from one Amazon OpenSearch Service domain to another, integrate dashboard authoring with existing CI/CD pipelines, or simply back up dashboards and visualizations.

If you have questions or suggestions, please leave a comment.


About the Author

Ryan Peterson is a Senior Solutions Architect at Amazon Web Services based in Irvine, CA. Ryan works closely with the Amazon CloudSearch and Amazon Elasticsearch Service teams, providing help and guidance to a broad range of customers that have search workloads they want to move to the AWS Cloud.