title: CloudWatch Logs Insights query syntax: How can I dynamically assign categories for a multi-line chart visualization?
body: <p>I want to visualize the memory usage of unique Lambda instances by plotting multi-line charts in Logs Insights.</p>
  <p>I can access logStream ID in my Logs Insights query using <code>@logStream</code></p>
  <p>I'd like to be able to plot a line showing memory usage for each different logStream ID over time, something like this:</p>
  <pre><code>fields @timestamp, @logStream, @maxMemoryUsed
  | filter @message like /REPORT/
  | sort @timestamp desc
  | stats @logStream, avg(@maxMemoryUsed) by bin(1m)
  </code></pre>
  <p>This produces a line showing average memory usage per minute, or a nice pie chart showing memory usage by LogStream per minute.</p>
  <p>I'd like a chart which shows a line for each separate LogStream ID though.</p>
  <p>Hardcoding in this case isn't an option as in the accepted answer to this question: <a href="https://stackoverflow.com/questions/57911181/how-can-i-visualize-timeseries-data-aggregated-by-more-than-one-dimension-on-aws">How can I visualize timeseries data aggregated by more than one dimension on AWS insights?</a></p>
  <p>The name of each line has to be assigned dynamically, as I can't control what the LogStream ID is, and I don't know how many there'll be for the time periods I'm interested in.</p>
  <p>I also note that the docs <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html</a> say that this is possible, but don't give an example of how.</p>