How do I calculate the time for a contact in the queue in Amazon Connect?

6 minute read

I want to calculate the time for a contact being spent in the queue in Amazon Connect.

Short description

You can calculate the time for a contact in the queue in Amazon Connect for active and completed contacts.

To calculate time spent in the queue for active contacts, use the following methods:

To calculate time spent in the queue for completed contacts, use the following methods:


For active contacts

Track QueueSize and LongestQueueWaitTime metrics

  1. Open the Amazon CloudWatch console.
  2. In the navigation pane, choose Metrics, and then choose All metrics.
  3. On the Metrics tab, choose Connect, and then choose Queue metrics.
  4. Select the metrics QueueSize and LongestQueueWaitTime.
  5. Choose the Graphed metrics tab. Then, for Statistic, choose Maximum.
  6. Review both the QueueSize and LongestQueueWaitTime.
    The QueueSize is the number of contacts in the queue. The LongestQueueWaitTime shows the longest amount of time in seconds that a contact waited in a queue. For more information, see Monitoring your instance using CloudWatch.

Tip: You can set a CloudWatch alarm on the LongestQueueWaitTime metric to get a notification if it reaches a certain threshold. For additional information, see Creating an alarm from a metric on a graph.

Use the GetCurrentMetricData API to track CONTACTS_IN_QUEUE and OLDEST_CONTACT_AGE

First, to find the QueueID and InstanceID for the API request parameters, do the following:

  1. Log in to your Amazon Connect instance using your access URL ( -or- You must use the administrator account or the emergency access Amazon Connect instance login.
  2. In the navigation menu, choose Routing, and then choose Queues.
  3. Choose the name of the queue that you want to review.
  4. In the Queue Details, choose the show additional queue information.
  5. Find the queue ARN shown as arn:aws:connect:region:account-id:instance/instance-id/queue/queue-id. Make note of the AWS Region, instance-id, and queue-id for the next steps.

Then, to run the GetCurrentMetricData API, do the following:

1.    Navigate to AWS CloudShell.

2.    Run the following AWS Command Line Interface (AWS CLI) command:
Note: Replace queue-id, instance-id, and region with your values.

aws connect get-current-metric-data --filters Queues=<queue-id> --instance-id <instance-id> --current-metrics Name=CONTACTS_IN_QUEUE,Unit=COUNT Name=OLDEST_CONTACT_AGE,Unit=SECONDS --groupings QUEUE --region <region>

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.

You receive an output similar to the following:

    "MetricResults": [
            "Dimensions": {
                "Queue": {
                    "Id": "<queue-id>",
                    "Arn": "<queue-arn>"
            "Collections": [
                    "Metric": {
                        "Name": "CONTACTS_IN_QUEUE",
                        "Unit": "COUNT"
                    "Value": 0.0
                    "Metric": {
                        "Name": "OLDEST_CONTACT_AGE",
                        "Unit": "SECONDS"
                    "Value": 0.0
    "DataSnapshotTime": "<The time at which the metrics were retrieved and cached for pagination.>"

Use contact events for tracking individual contacts

1.    Open the Amazon EventBridge console.

2.    In the navigation pane, choose Rules.

3.    Choose Create rule.

4.    For Rule type, choose Rule with an event pattern.

5.    Choose Next.

6.    In the Creation Method, choose Use pattern form.

7.    In the Event pattern, select Event source as AWS Services, AWS Service as Amazon Connect, and Event Type as Amazon Connect Contact Event.

8.    Under Target1, choose Target type as AWS Service.

9.    Under Select a target, choose Lambda function. For the function, do the following:
Create a Lambda function with the console, using runtime Python 3.8.
For the Lambda function code, use the following:

import json
def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')

Note: The Lambda function prints all events and is intended for testing. The process to calculate the time spent by a specific contact in a queue must be set up manually.

10.    Choose Skip to Review and create, and then choose Create rule.

11.    Access the Amazon CloudWatch logs for AWS Lambda to see a near real-time stream of contacts, such as, voice calls, chat, and task events. For example, you can see if a call is queued in your Amazon Connect contact center.
Note: Available contact events are INITIATED, CONNECTED_TO_SYSTEM, QUEUED, CONNECTED_TO_AGENT, and DISCONNECTED. Events are released on a best effort basis.

12.    To determine the time spent by a specific contact in the queue, first locate the following information:

  • The QUEUED event timestamp for a specific contact ID.
  • The CONNECTED_TO_AGENT event timestamp for the same contact ID.

13.    To calculate the time spent by the specific contact in the queue, subtract the QUEUED timestamp from the CONNECTED_TO_AGENT timestamp.

For completed contacts

Track queued time using historical metrics

To view the historical metric reports, do the following:

  1. Log in to your Amazon Connect instance using your access URL ( -or-
    Important: You must log in as a user that has sufficient permissions required to view historical metrics reports.
  2. In the navigation menu, choose Analytics and optimization, Historical metrics.
  3. Choose the Queues report type.
  4. Choose the gear icon.
  5. On the Metrics tab, choose Maximum queued time.
  6. On the Interval & Time range tab, set the Interval, Time Zone, and Time range.
  7. When you're finished customizing your report, choose Apply. The Maximum queued time shows the longest time that a contact spent waiting in the queue for the selected interval and time range.
  8. (Optional) To save your report for future use, choose Save, provide a name for the report, and then choose Save.
    Tip: You can schedule a historical metrics report for future use.

You can also use the GetMetricData API to track QUEUED_TIME. The GetMetricData API metrics are available for only a 24 hour duration.

Track duration in the QueueInfo using the contact search for individual contacts

To use the contact search, do the following:

  1. View a contact record in the UI to open the contact trace record (CTR) that you want to view.
  2. If the contact was queued, then the Queue section populates and lists the duration of time the contact spent in the queue. Note: Data retention for CTR is 24 months upon contact initiation.
  3. To retain contact data for longer than 24 months, stream the CTRs using the following method:
    Create an Amazon Kinesis Data Firehose delivery stream or an Amazon Kinesis data stream. Then, activate data streaming in your instance.
    Note: For an alternate method, see Analyze Amazon Connect contact trace record with Amazon Athena and Amazon QuickSight.

AWS OFFICIALUpdated a month ago