LoginSignup
1
0

More than 1 year has passed since last update.

AWS OpenSearch Dashboard REST API

Last updated at Posted at 2022-09-02

OpenSearchのドキュメントが足りない!!

盗人猛々しいのかもしれないAWSのOpenSearchのダッシュボード周りのAPIが見つからなくて困って探したので、その結果を共有します。
WebGUIを手で操作とか死ねます。

Use the Source, Luke.

凡例

  • $ENDPOINT エンドポイントのホスト名
    e.g. search-hogehoge-fugafuga.ap-west-5.es.amazonaws.com
  • $USER ユーザ名
  • $PASS パスワード
resource "aws_elasticsearch_domain" "hogehoge" {
  elasticsearch_version = "OpenSearch_1.3"
  advanced_security_options {
    enabled = true
    internal_user_database_enabled = true
    master_user_options {
      master_user_name = local.opensearch_user
      master_user_password = local.opensearch_pass
    }
  }
  #中略
}

output "opensearch_endpoint" {
  value = aws_elasticsearch_domain.hogehoge.endpoint
}

APIの認証情報をゲットだぜ

クッキーをもらいます。

curl --cookie-jar auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -d "{\"username\":\"$USER\", \"password\":\"$PASS\"}" \
  -X POST \
  https://$ENDPOINT/_dashboards/auth/login \
  | jq

auth.txtに入ったクッキーをこれから使います。

オブジェクトタイプの一覧

curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -X GET \
  https://$ENDPOINT/_dashboards/api/opensearch-dashboards/management/saved_objects/_allowed_types \
   | jq

OpenSearch1.3の場合

{
  "types": [
    "config",
    "url",
    "index-pattern",
    "query",
    "dashboard",
    "visualization",
    "search"
  ]
}

以下dashboardでやりますが他も同じです。

ダッシュボードの一覧

以下グローバルテナントの場合。

curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -H "securitytenant: global" \
  -X GET \
  https://$ENDPOINT/_dashboards/api/opensearch-dashboards/management/saved_objects/_find?type=dashboard \
  | jq

以下操作対象のダッシュボードのUUIDを$IDとします。

non legacy

ダッシュボードのエクスポート

curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -H "securitytenant: global" \
  -X GET \
  https://$ENDPOINT/_dashboards/api/opensearch-dashboards/management/saved_objects/dashboard/$ID \
  -o dashboard.json

ダッシュボードのインポート

ないっぽい?

legacy

なぜlegacyかというと、ソースのpathにlegacyが含まれるから。

ダッシュボードのエクスポート

curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -H "securitytenant: global" \
  -X GET \
  https://$ENDPOINT/_dashboards/api/opensearch-dashboards/dashboards/export?dashboard=$ID \
  -o dashboard.json

ダッシュボードのインポート

curl --cookie auth.txt \
  -H "osd-xsrf: true" \
  -H "content-type: application/json" \
  -H "securitytenant: global" \
  -X POST \
  https://$ENDPOINT/_dashboards/api/opensearch-dashboards/dashboards/import \
  -d dashboard.json

ドキュメント

どれもそこそこ参考になります。そこそこ。

awsの資料

github issue:open

ソースからAPIのpathを探す方法

grep "path:" OpenSearch-Dashboards-1.3.4/src/plugins/*/server/routes/*
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0