Amazon QuickSightがAPI操作できるようになりました #reinvent

AWSが提供するクラウド型BIサービスAmazon QuickSightがAPI操作に対応しました。
2018.11.28

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

この記事は2018年11月24日時点の動作をもとに執筆しています。

AWSが提供するクラウド型BIサービスAmazon QuickSightがAPI操作に対応しました。

Amazon QuickSight adds support for dashboard embedding and APIs

提供API一覧

AWS CLI ではバージョン 1.16.59 から QuickSight の API に対応しています。

同バージョンでは

  • ユーザー管理
  • ダッシュボード埋め込み

の API のみに対応しています。

具体的には、以下の通りです。

ユーザー管理 API

  • create-group
  • create-group-membership
  • delete-group
  • delete-group-membership
  • delete-user
  • describe-group
  • describe-user
  • list-groups
  • list-group-memberships
  • list-user-groups
  • list-users
  • register-user
  • update-group
  • update-user

ダッシュボード埋め込み API

  • get-dashboard-embed-url

AWS CLI からユーザーを操作してみた

公開された API を利用して AWS CLI から実際に QuickSight の READER ロールのユーザーを操作します。

登録フロー

ユーザーを作成

register-user API でユーザーを作成します。

$ aws quicksight register-user \
  --aws-account-id 123456789012 \
  --namespace default \
  --identity-type QUICKSIGHT \
  --email foo@example.com \
  --user-name foo@example.com \
  --user-role READER
{
    "Status": 201,
    "User": {
        "Arn": "arn:aws:quicksight:us-east-1:123456789012:user/default/foo@example.com",
        "UserName": "foo@example.com",
        "Email": "foo@example.com",
        "Role": "READER",
        "Active": false
    },
    "RequestId": "42536235-f1b1-4a56-9777-e31106549bb1"
}
パラメーター 意味
--aws-account-id アカウントID
--namespace ネームスペース。"default"を指定
--identity-type IAMのユーザーをQuickSightで利用する場合は"IAM"、QuickSightのユーザー管理に新規ユーザーを作成する場合は"QUICKSIGHT"を指定
--email ユーザーのメールアドレス
--user-name ユーザー名
--user-role ユーザーのロールを"ADMIN/AUTHOR/READER"から指定

ユーザーを確認

管理画面を確認すると、INACTIVE なユーザーとして登録されています。

API でもユーザー状態を確認します。

ユーザー一覧は list-users API で確認します。

$ aws quicksight list-users \
  --aws-account-id 123456789012 \
  --namespace default
{
    "Status": 200,
    "UserList": [
        {
            "Arn": "arn:aws:quicksight:us-east-1:123456789012:user/default/foo@example.com",
            "UserName": "foo@example.com",
            "Email": "foo@example.com",
            "Role": "READER",
            "Active": false
        },
        {
            "Arn": "arn:aws:quicksight:us-east-1:123456789012:user/default/dummy",
            "UserName": "dummy",
            "Email": "dummy@exaple.com",
            "Role": "ADMIN",
            "Active": true
        }
    ],
    "RequestId": "da8865ca-2146-4344-87ce-dfa778624da3"
}

登録したユーザーの詳細を describe-user API で確認します。

$ aws quicksight describe-user \
  --aws-account-id 123456789012 \
  --namespace default \
  --user-name foo@example.com
{
    "Status": 200,
    "User": {
        "Arn": "arn:aws:quicksight:us-east-1:123456789012:user/default/foo@example.com",
        "UserName": "foo@example.com",
        "Email": "foo@example.com",
        "Role": "READER",
        "Active": false
    },
    "RequestId": "6180ceb3-e3e2-4aa0-a397-623efcd4ebc2"
}

ユーザーをアクティベート

QuickSight のユーザー管理機構を利用して作成したユーザーは、メール経由でアクティベートします。

API を利用してユーザー登録すると招待メールが届かなかったため、管理画面から "Resend invitation" のリンクをクリックして招待メールを送信しました。

次の様なメールが届くため、"Click to accept invitation" のリンクをクリックし、登録手続きを進めます。

アクティベート済みのユーザーを確認すると、 "Active": true に変わっています。

$ aws quicksight describe-user \
  --aws-account-id 123456789012 \
  --namespace default \
  --user-name foo@example.com
{
    "Status": 200,
    "User": {
        "Arn": "arn:aws:quicksight:us-east-1:123456789012:user/default/foo@example.com",
        "UserName": "foo@example.com",
        "Email": "foo@example.com",
        "Role": "READER",
        "Active": true
    },
    "RequestId": "98b62d28-49d8-45e4-8393-f04ccba1a262"
}

ユーザーの削除

最後に、delete-user API でユーザーを削除します。

$ aws quicksight delete-user \
  --aws-account-id 123456789012 \
  --namespace default \
  --user-name foo@example.com
{
    "Status": 204
}

レスポンスのHTTP ステータスについて

QuickSight 用 API のレスポンスには、どういうわけか HTTP ステータスコードが含まれています

register-user(リソースの作成) は 201:Created, delete-user(リソースの削除)は 204:No Content です。

RESTful ですね。

最後に

API にも CloudFormation にも対応していなかった Amazon QuickSight は、構築の省力化が難しいAWSサービスの一つでした。

現時点では一部の機能しか API 提供されていませんが、データセット含め API に順次対応し、構築が省力化されていくことが期待されます。

API の制限事項など仕様の詳細は後日補足したいと思います。

それでは。

参考