title: Search AWS CLI output and save to variable
body: <p>I'm very new to batch files, but I'm trying to use one to automate some AWS CLI instance-creation.</p>
  
  <p>What I have is pretty simple so far -- I have a command in my <code>.bat</code> file that will run the <code>run-instances</code> command:</p>
  
  <pre><code>aws ec2 run-instances --dry-run --image-id %ami_id% --key-name %keypair% --security-group-ids %security_group% --instance-type "r3.large" --subnet-id %az1b_subnet%
  </code></pre>
  
  <p>This command takes a little bit to run, but will eventually (without the <code>--dry-run</code>) return json about the created instance(s).  I'd like to search that json output and save the <code>instance-id</code> to a variable so that I can use it to tag my newly created instance with the <code>ec2 create-tags</code> command.</p>
  
  <p>Any thoughts on how I could do that?  My first attempt was to add <code>&gt; test.txt</code> to the end of the above command and then search through the json and set the variable. However, the <code>test.txt</code> is created instantly before the CLI command has finished and returned its output.</p>
  
  <p>Thanks.</p>