Curious (Clojure) Programmer Simplicity matters

Menu

  • Home
  • Archives
  • Tags
  • About
  • My Talks
  • Clojure Tip of the Day Screencast
  • (Open) Source
  • Weekly Bits & Pieces
  • RSS
January 18, 2022

AWS Cloudwatch Insights and Unix Timestamps

For way too long, I’ve been frustrated by inability of the Cloudwatch Insights UI console to produce human-readable output of latest/earliest functions.

Consider this example: [1]

fields @timestamp, @message
| parse /version=(?<my_version>\d\.\d.\d)/
| stats latest(@timestamp) as latest_version_check,
  count(@message) as checks_count
  by my_version
| sort by latest_version_check desc
| display latest_version_check, my_version, checks_count

This produces a table where the latest_version_check will be formatted as a plain unix timestamp (in milliseconds):

unix timestamps

Having a human-readable date/time would be so much more useful!

The solution/workaround

I wrote a small piece of JavaScript which I can quickly copy-paste into browser’s Dev Tools console:

// paste this into browser's JS console - adjust CSS class name as needed
document.getElementsByClassName("logs-table__body-cell").forEach( // (1)
  function(element) {
    var content = element.textContent
    timestamp = parseInt(content);
    if (!isNaN(timestamp) && timestamp > 1000000000) {
      var humanDate = new Date(timestamp).toLocaleString();
      console.log(timestamp + " => " + humanDate);
      // replace timestamp with human-readable date
      element.innerHTML = humanDate;
  }
});
  1. logs-table__body-cell is the CSS class name that the UI uses for cells in the result table. If the script doesn’t work, make sure to open the insepector and check the cell class name.

Now it looks much better!

human dates

1. I did try using tomillis function as suggested in the thread reply but it didn’t work - it still shows up as a number, not a date

Tags: aws snippets javascript

« Weekly Bits 01/2022 - analyzing dependencies with clj-kondo, AWS architect mindset, 5 JavaScript features you should learn Moving My Blog to Cryogen and Cloudflare Pages »

Copyright © 2025 Juraj Martinka

Powered by Cryogen | Free Website Template by Download Website Templates