LoginSignup
3
0

More than 1 year has passed since last update.

【AWS CLI】オプションにURLを指定した際に、received non 200 status code of XXXと表示される場合の対処法

Posted at

はじめに

掲題の通り、AWS CLI の v1 にて、オプションに URL を指定した際に、received non 200 status code of XXX というエラーが表示されることがあります。
その原因と対処法をまとめました。

# create-custom-verification-email-template 実行時に遭遇しました
$ aws ses create-custom-verification-email-template \
     --template-name "dummy" \
     --from-email-address "dummy@example.co.jp" \
     --template-subject "dummy" \
     --template-content "content" \
     --success-redirection-url "https://www.example.com/verifysuccess" \
     --failure-redirection-url "https://www.example.com/verifyfailure"

Error parsing parameter '--success-redirection-url': Unable to retrieve https://www.example.com/verifysuccess: received non 200 status code of 404

環境

$ aws --version
aws-cli/1.19.104 Python/3.7.10 Linux/4.14.225-168.357.amzn2.x86_64 exec-env/CloudShell botocore/1.20.104

原因

AWS CLI の v1 では、http://, https:// でパラメータが始まる場合、その URL からロードしたファイルを、URL の代わりのパラメータとして扱います。

AWS CLI は、http:// または https:// の URL でインターネット上にホストされているファイルからのパラメーターのロードもサポートしています。次の例では、Amazon S3 バケットに格納されているファイルを参照しています。これにより、任意のコンピュータからパラメータファイルにアクセスできますが、コンテナが公開されている必要があります。

参考: ファイルから AWS CLI パラメーターをロードする - AWS コマンドラインインターフェイス

その時、200 以外のステータスコード が返却された場合、取得に失敗したと判断してエラーを出力します。
これが received non 200 status code of XXX というエラーになります。

対処法

1. ~/.aws/credentialscli_follow_urlparam = false を追記する

以下にあるように、cli_follow_urlparam = falseを指定すると、http://, https:// で始まる文字列を通常の文字列パラメーターとして処理するようになります。

With this configured the CLI will follow any string parameters that start with https:// or http:// will be fetched, and the downloaded content will be used as the parameter instead.
false - The CLI will not treat strings prefixed with https:// or http:// any differently than normal string parameters.

参考: AWS CLI Configuration Variables — AWS CLI 1.19.104 Command Reference

逆にいえば、こちらのパラメータがデフォルトでtrueとなっているため、上記の処理が実行されます。

2. --cli-input-jsonオプションを使用し、json 形式でパラメータを渡す

json 形式で値を渡すことで、上記の処理をスルーすることができます。

$ echo '{
    "TemplateName": "dummy",
    "FromEmailAddress": "dummy@example.co.jp",
    "TemplateSubject": "dummy",
    "TemplateContent": "content",
    "SuccessRedirectionURL": "https://www.example.com/verifysuccess",
    "FailureRedirectionURL": "https://www.example.com/verifysuccess"
}' > dummy.json
$ aws ses create-custom-verification-email-template --cli-input-json file://dummy.json
# エラーなし

3. AWS CLI の v2 を使用する

以下のように、AWS CLI v2 ではcli_follow_urlparamが固定で false になっています。
そのため、設定を変更せずともhttp://, https:// で始まる文字列を通常の文字列パラメーターとして処理できます。

AWS CLI version 2: false. In the AWS CLI version 2 you can't change this setting.

参考: cli_follow_urlparam - AWS SDKs and Tools

3
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
3
0