[TreasureData]tdコマンド実行でTreasureData::AuthErrorエラーになる場合の対処


TreasureData::AuthError について

tdコマンド実行でTreasureData::AuthErrorがでる場合はエンドポイントの設定が漏れていることが多い。

$ td db:list
Error: TreasureData::AuthError - List databases failed: Failed to Login

TreasureData tdコマンド実行するには

公式サイトからダウンロード&インストール

公式サイトからダウンロードし、インストールする。

インストール完了したら、 td --version でインストールの確認を行う。

$ td --version
0.16.4

エンドポイントの設定する

契約しているのが本家 (treasuredata.com) 以外の場合
デフォルトのエンドポイントのままでは接続できないため、以下のコマンドからエンドポイントを設定する。
(今回は treasuredata.co.jp の場合)

$ td server:endpoint https://api.treasuredata.co.jp/

設定しない場合 毎回tdコマンドに -e https://api.treasuredata.co.jp/ が必要となる。
ただし、クライアントサイドのコマンドにしか有効ではなくサーバサイドのコマンドの場合は
上記を設定しても 毎回tdコマンドに -e https://api.treasuredata.co.jp/ が必要となる。
なんとかならないものか。。。

アカウント情報の設定

$ td account

一度作成した場合はエラーがでるので -f オプションを付けて実行

$ td account
Account is already configured with '[email protected]' account.
Add '-f' option to overwrite.
$ td account -f
Enter your Treasure Data credentials.
Email: [ログイン用メールアドレスを入力]
Password (typing will be hidden): [ログイン用パスワードを入力]
Authenticated successfully.
Use 'td db:create <db_name>' to create a database.

td db:listコマンドでdb一覧が取得できれば接続完了

$ td db:list
+----------------------+----------+
| Name                 | Count    |
+----------------------+----------+
| sample_datasets      | 0        |
| information_schema   | 0        |
+----------------------+----------+
2 rows in set

設定が完了されると以下にファイルが保存されている。
endpointを消すとTreasureData::AuthErrorが発生するようになる。

$ cat ~/.td/td.conf
[account]
  endpoint = https://api.treasuredata.co.jp/
  user = [email protected]
  apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx