Category

Passing JSON as parameter to AWS CLI

31 / Jan / 2014 by Tejprakash Sharma 0 comments

While working with the new AWS CLI, you might come up with a use case in which complex values are required as an input. To simplify things a bit AWS CLI allows you to pass JSON as an input to argument.

For example, to pass parameters to the –block-device-mappings parameter in the aws ec2 create-image command, you need to format the block device information as JSON. It is definitely easier to pass JSON than a complex structure to CLI.

You can either of the two methods mentioned below to pass JSON file as parameter to AWS CLI. One is to pass JSON file with complete path using  file://  prefix, as shown in the example.
aws ec2 create-image --instance-id &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;quot;instance-id&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;quot; --block-device-mappings file://\path\to\file-name.json
Another approach is to pass JSON file from a S3 bucket with complete URL to the file by using either the http:// or https:// prefix. It is also useful as you can create a central repository for input parameter and access it from anywhere.
aws ec2 create-image  --instance-id &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;quot;instance-id&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;quot;--block-device-mappings http://bucketname.s3.amazonaws.com/file-name.json
FOUND THIS USEFUL? SHARE IT
Services