5

I'm trying to create a CloudWatch Insights query for Amazon Connect that will give me call counts by date. I'm able to get the number of log messages by date, however, I need to only count unique ContactId's. The query I have has many duplicated ContactId's since each time Connect logs to CloudWatch, it uses ContactId to tie all of the events related to a contact together. Is there a way to modify this query to only show the count of the unique ContactId?

filter @message like /ContactId/
| stats count(*) as callCount by toMillis(datefloor(1d))
| sort callCount desc
TimWagaman
  • 980
  • 1
  • 10
  • 31

1 Answers1

5

Embarassingly enough, almost immediately after posting this, I found my answer. count_distinct() gets me what I needed.

filter @message like /ContactId/
| stats count_distinct(ContactId) as callCount by toMillis(datefloor(1d))
| sort callCount desc
TimWagaman
  • 980
  • 1
  • 10
  • 31
  • 3
    I think datefloor function expects two values; timestamp and period. Thus the query would change to - ```filter @message like /ContactId/ | stats count_distinct(ContactId) as callCount by toMillis(datefloor(@timestamp, 1d)) | sort callCount desc``` – Sunny Tambi May 05 '21 at 07:04