{"id":11607,"date":"2014-01-31T16:53:46","date_gmt":"2014-01-31T11:23:46","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11607"},"modified":"2017-01-18T19:57:47","modified_gmt":"2017-01-18T14:27:47","slug":"passing-json-as-parameter-to-aws-cli","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/passing-json-as-parameter-to-aws-cli\/","title":{"rendered":"Passing JSON as parameter to AWS CLI"},"content":{"rendered":"<p>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.<\/p>\n<p>For example, to pass parameters to the\u00a0<strong>&#8211;block-device-mappings<\/strong>\u00a0parameter in the\u00a0<strong>aws ec2 create-image<\/strong>\u00a0command, you need to format the block device information as JSON. It is definitely easier to pass JSON than a complex structure to CLI.<\/p>\n<div><\/div>\n<div>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 \u00a0file:\/\/\u00a0 prefix, as shown in the example.<\/div>\n<div><\/div>\n<div>[shell]aws ec2 create-image &#8211;instance-id &amp;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;amp;quot; &#8211;block-device-mappings file:\/\/\\path\\to\\file-name.json[\/shell]<\/p>\n<\/div>\n<div><\/div>\n<div>Another approach is to pass JSON file from a S3 bucket with complete URL\u00a0to the file by using either the\u00a0<strong>http:\/\/<\/strong>\u00a0or\u00a0<strong>https:\/\/<\/strong>\u00a0prefix. It is also useful as you can create a central repository for input parameter and access it from anywhere.<\/div>\n<div><\/div>\n<div>[shell]<br \/>\naws ec2 create-image  &#8211;instance-id &amp;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;amp;quot;&#8211;block-device-mappings http:\/\/bucketname.s3.amazonaws.com\/file-name.json[\/shell]<\/p>\n<\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0&#8211;block-device-mappings\u00a0parameter in the\u00a0aws ec2 create-image\u00a0command, you need to [&hellip;]<\/p>\n","protected":false},"author":678,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":29},"categories":[1174],"tags":[1297,1296,1295],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11607"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/678"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11607"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11607\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}