LoginSignup
1
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2019-06-19

はじめに

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のせいで公式ドキュメントから外れてしまったので、初心者のわたしには難しかった

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