LoginSignup
7
2

More than 3 years have passed since last update.

コマンドプロンプトでAWS CLIを使うときのJSONの取り扱い

Last updated at Posted at 2019-07-06

意外と忘れてハマりがちなので。

コマンドプロンプトでAWS CLIを使うときにJSONをそのままコマンドラインに記述すると上手くいきません。

$aws dynamodb  put-item --table-name Animals --item '{"id":{"S":"a"},"name":{"S":"dog"}}'

Linuxシェルなら上記の記述で大丈夫ですが。

>aws dynamodb  put-item --table-name Animals --item '{"id":{"S":"a"},"name":{"S":"dog"}}'

Error parsing parameter '--item': Expected: '=', received: ''' for input:
'{id:{S:a},name:{S:dog}}'

コマンドプロンプトだと引用符の扱いが異なるため、エラーになってしまいます。

>aws dynamodb  put-item --table-name Animals --item "{\"id\":{\"S\":\"a\"},\"name\":{\"S\":\"dog\"}}"

このように一番外側を二重引用符で囲って中のものはエスケープしてやると上手くいきます。

>type put.json
{"id":{"S":"a"},"name":{"S":"dog"}}
>aws dynamodb  put-item --table-name Animals --item file://put.json

外部ファイルに書いてやれば気にしなくてよいのでこちらの方がスマートですね。

7
2
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
7
2