title: Aws batch: sending log for a specific command to cloudwatch
body: <p>I run an aws batch jobs. For that i use a python script. This script also runs bash subprocesses.
  I used the following function to put message on stdout:</p>
  <pre><code>def printf(msg):
      print(msg, file=sys.stdout)
      sys.stdout.flush()
  </code></pre>
  <p>And for exemple :</p>
  <pre><code>printf('Downloading misc inputs')
  </code></pre>
  <p>With this i can send some messages to aws cloudwatch.</p>
  <p>But i would like to know if there is a way to send the log of one specific Bash command to a specific cloudwatch stream ?</p>
  <p>To exec my Bash command i use the function:</p>
  <pre><code>def exec_cmd(cmd, shell=True):
      printf(&quot;Executing %s&quot; % cmd.strip())
  
      if not shell:
          p = subprocess.Popen(cmd.split())
      else:
          p = subprocess.Popen(cmd, shell=True, executable='/bin/bash')
  
      err = p.wait()
      return err
  </code></pre>
  <p>And then :</p>
  <pre><code>my_command1 = &quot;/usr/local/bin/mytool arg1 arg2 &gt; /ephemaral/output/log_command1.log 2&gt;&amp;1&quot;
  
  Exit_code1 = exec_cmd(my_command1)
  
  my_command2 = &quot;/usr/local/bin/mytool arg1 arg2 &gt; /ephemaral/output/log_command2.log 2&gt;&amp;1&quot;
  
  Exit_code2 = exec_cmd(my_command2)
  </code></pre>
  <p>I want to know if i can send in Real time the content of log_command1.log to one cloudwatch stream, and the content of log_command2 to another cloudwatch stream.</p>