LoginSignup
3
2

More than 5 years have passed since last update.

awscliにヒアドキュメントを渡す

Posted at

awscliのバージョン1.0で
軽い文章とシェルコマンドの実行結果を
メールの本文で送りたいときに
軽くはまったのでメモ。

awscliにshell形式のヒアドキュメントを
渡しても引数が正しく解釈されずにエラーになる。

$ aws ses send-mail --from hoge@mail.com --to fuga@mail.com --subject 'タイトル' --text <<CODE
こんなにいっぱい
`df -h # shell script here`
CODE

usage: aws [options] <command> <subcommand> [parameters]
aws: error: argument --text: expected one argument

awscliはPythonでできているためPythonの形式で
ヒアドキュメントを渡してあげると無事出力される。

aws ses send-mail --subject "タイトル" --text """\
こんなにいっぱい
`df -h # shell script here`
"""

ただしコマンドの実行結果を本文に紛れ込ませたいときは
シェルと同様にバッククォートで埋め込まないと
認識してくれない。謎。

3
2
2

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
2