■ はじめに
EMR から Glue workflow を実行することになったので、 AWS Glue に関する AWS CLI について、メモっておく。
目次
【0】API仕様 【1】ヘルプを表示するには 【2】AWS CLI 使用例 1)Glue Workflow を実行するには 2)Glue Connection を取得するには 3)Get Tables を実行するには 【3】使用上の注意
【0】API仕様
* 以下の公式サイトを参照
https://docs.aws.amazon.com/cli/latest/reference/glue/index.html https://docs.aws.amazon.com/ja_jp/glue/latest/dg/aws-glue-api.html
【1】ヘルプを表示するには
aws glue help aws glue <API Name> help
コマンド例
# API「create-workflow」を表示する aws glue create-workflow help # API「get-tables」を表示する aws glue get-tables help
【2】AWS CLI 使用例
1)Glue Workflow を実行するには
aws glue start-workflow-run --name <Workflow Name>
API仕様
https://docs.aws.amazon.com/cli/latest/reference/glue/start-workflow-run.html
コマンド例
# Workflow Name「sample-glue-workflow」を実行 aws glue start-workflow-run --name sample-glue-workflow
2)Glue Connection を取得するには
aws glue get-connection --name <Glue Connection Name> => 取得したレスポンスを jq コマンド でパースして取得する => jqコマンドについては、以下の関連記事を参照のこと。
https://dk521123.hatenablog.com/entry/2020/02/01/000000
API仕様
https://docs.aws.amazon.com/ja_jp/cli/latest/reference/glue/get-connection.html
コマンド例
# Glue Connection Name「sample-glue-connection (Password含め)」を取得する connection_info=`aws glue get-connection --name sample-glue-connection --no-hide-password | jq .Connection.ConnectionProperties`
3)Get Tables を実行するには
* Glue Data Catalog table の情報を取得する aws glue get-tables --database-name <DB Name>
API仕様
https://docs.aws.amazon.com/cli/latest/reference/glue/get-tables.html
コマンド例
# aws glue get-tables --database-name <DB Name> aws glue get-tables --database-name sample_db # Regionを指定する場合 # => エラー「You must specify a region. # You can also configure your region by running "aws configure".」対策 aws glue get-tables --database-name sample_db --region us-west-2
【3】使用上の注意
* AWS CLI の Version によっては、実装されていないAPIもある。
実例
AWS EMR から AWS CLI の「aws glue get-workflow-run」を実行したところ 「aws: error: argument operation: Invalid choice, valid choices are: ...」が表示された
調査詳細
* AWS EMR を起動して、SSH接続でアクセスし実行しても同様の結果。 * 「aws glue help」で確認したところ、 「aws glue start-workflow-run」がなかった << ★ここ★ * 念のため、「aws glue start-workflow-run help」で確認したところ、 エラーになる * ちなみに、「aws --version」で確認したところ、 「aws-cli/1.16.102」だった。
解決案
1)AWS CLI の Upgrade 2)boto3が使えるなら、Pythonで「start_workflow_run」を実行する などなど...
参考文献
関連記事
AWS Glue ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/01/221926
AWS Glue ~ Boto3 / 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/14/000000
jq コマンド ~ コマンドで JSON を扱う ~
https://dk521123.hatenablog.com/entry/2020/02/01/000000
psqlでパスワードを省略する
https://dk521123.hatenablog.com/entry/2020/03/06/000000