Amazon ForecastのためにAWS CLIの設定をする

はじめに

Amazon Forecastでデータをcsvダウンロードしたいけれど、コンソールでできなさそうなので、AWS CLIを使いたい。

saml2awsでログインする

[AWS] SAMLで認証しているユーザーの権限でAWS CLIを実行する

Amazon Forecast のアクセス許可を設定する

Amazon Forecast のアクセス許可を設定する
作成した ロール > ForecastRole のロール ARNが後で必要になるので、メモ

確認

既にコンソールで作成済みの予測子のリストを取得して、問題なく設定できているか確認してみる
※ regionとprofileのオプションの指定が必要

aws --region us-east-1 --profile saml forecast list-predictors

作成したpredictor一覧が返ってくる

{
    "PredictorNames": [
        "predictor_name_xxxx",
        "predictor_name_yyyy", 
        "predictor_name_zzzz"
    ]
}

S3にエクスポート

公式ドキュメントより

a. 予測エクスポートジョブを作成します。

aws forecast create-forecast-export-job \
--forecast-id forecast-id \
--output-path '{"S3Uri":"s3://bucket-name","RoleArn":"roleArn"}'

forecast-id, S3のパス, RoleArn が必要

forecast-id

使いたいpredictorの名前を指定して、IDを取得する

aws --region us-east-1 --profile saml forecast list-forecasts --predictor-name predictor_name_xxxx

レスポンス

{
    "ForecastInfoList": [
        {
            "PredictorName": "predictor_name_xxxx", 
            "VersionId": "88....b0", 
            "ForecastId": "155.........e6c"
        }
    ]
}

S3のパス

s3://bucket-name/

RoleArn

arn:aws:iam::9.........4:role/ForecastRole

Amazon Forecast のアクセス許可を設定する でメモしたロール ARNを使う

いざエクスポート

aws forecast create-forecast-export-job \
--forecast-id 155.........e6c \
--output-path '{"S3Uri":"s3://bucket-name","RoleArn":"arn:aws:iam::9.........4:role/ForecastRole"}'

進捗はいかがか聞いてみて、

aws --region us-east-1 --profile saml forecast describe-forecast-export-job --forecast-export-job-id 8......2

"Status": "ACTIVE"と返ってきたら、S3に結果が出力されている!

さいごに

saml2のせいで公式ドキュメントから外れてしまったので、初心者のわたしには難しかった

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account