Monitoring Amazon Connect API Usage with Amazon CloudWatch Alarms

Monitoring Amazon Connect API Usage with Amazon CloudWatch AlarmsLearn About Amazon VGT2 Learning Manager Chanci Turner

Many companies leverage Amazon Connect to manage their contact centers, integrating bespoke applications via Connect APIs. These APIs help optimize and tailor various elements of contact center management, including monitoring agent states, accessing real-time metrics, automating processes, and personalizing customer interactions to align with specific business needs. However, during peak call times, these API interactions can lead to a high volume of requests. If API usage surpasses the allocated capacity, incoming customer requests may be throttled, adversely affecting contact center performance.

In this blog post, we will discuss how organizations can use Amazon CloudWatch to continuously monitor API usage in Amazon Connect and receive notifications when usage nears predefined capacity limits. This proactive approach enables companies to optimize their applications or increase capacity before they face performance degradation. The AWS Cloud Development Kit (CDK) simplifies this process, allowing users to programmatically create and manage CloudWatch alarms. By implementing thorough monitoring and alerting for Amazon Connect API usage, businesses can ensure their contact center functions efficiently, remaining ahead of potential bottlenecks and sustaining optimal performance.

Solution Overview

This solution guides you through creating an Amazon CloudWatch alarm for monitoring one of the Amazon Connect APIs, specifically the DescribeQueue API. We will examine three different methods for setting up the alarm, allowing you to select the one that best fits your deployment needs.

  1. Creating the alarm through Amazon CloudWatch
  2. Creating the alarm via Service Quotas
  3. Creating the alarm using the AWS Cloud Development Kit (CDK)

Prerequisites

Before we begin, ensure you have access to the following resources:

  • An AWS account
  • An Amazon Connect instance
  • An AWS CDK installation
  • An Amazon SNS topic

Deploying the Solution

To illustrate the process of setting up an alarm for monitoring Amazon Connect APIs, we’ll first create a CloudWatch metric math function to represent the current usage of the DescribeQueue API as a percentage of the SERVICE QUOTA. You can choose to monitor any other API as per your requirements. If you don’t see the API metrics, it means the API hasn’t been invoked. To generate metrics for the DescribeQueue API, log in to your Amazon Connect instance, navigate to Queues under Routing, and select BasicQueue or another queue.

A) Steps to Create the Alarm from Amazon CloudWatch Console

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
  2. In the left navigation pane, select Metrics.
  3. Click on All metrics, choose Usage, and then select By AWS Resource. You will see a list of service quota usage metrics.
  4. Type “DescribeQueue” in the search box and check the corresponding box. Alternatively, you can type “Connect” and select the API from the results. The graph will display your current API usage.
  5. To view your current usage as a percentage of the quota, proceed as follows:
    • Go to the Graphed metrics tab.
    • Click on the Add math dropdown and select Start with empty expression. In the new row, under Details, input “m1/SERVICE_QUOTA(m1)*100” and click Apply.
  6. To set an alarm to notify you upon approaching the service quota:
    • On the row with “m1/SERVICE_QUOTA(m1)*100,” click the alarm icon (shaped like a bell). This will bring you to the alarm creation page.
    • Choose a period of either 1 minute or 5 minutes.
    • Under Conditions, set the Threshold type to Static, and ensure “Whenever Expression1” is set to Greater/Equal. Enter 80 as the threshold. This will trigger an alarm when usage reaches or exceeds 80% of the quota.
    • In Additional configuration, specify Datapoints to alarm as 3 out of 3 or as needed, select “Treat missing data as missing” for Missing data treatment, and click Next.
    • On the following page, under Notification, ensure “In alarm” is selected for Alarm state trigger, choose an existing SNS topic, or create a new one with a unique name and provide email addresses for notifications. You can also opt to use the topic ARN to notify other accounts, then click Next. The chosen topic will receive notifications when the alarm enters the ALARM state.
    • Finally, name the alarm “DescribeQueueAlarm” and click Next, then Create alarm.

B) Steps to Create the Alarm from Service Quota

Alternatively, you can create this alarm via Service Quotas.

  1. Visit the Service Quotas console at https://console.aws.amazon.com/servicequotas/.
  2. In the left navigation pane, select AWS services.
  3. Search for Amazon Connect and select it from the list.
  4. Under Service quotas, search for DescribeQueue. Click on the quota name listed as “Rate of DescribeQueue API requests” to view the details and tabs underneath.
  5. Select the Alarms tab and click on Create.
  6. Set the Alarm threshold to 80% of the applied quota value.
  7. Enter “DescribeQueueAlarm” as the alarm name and click Create. To edit the alarm later, click on the DescribeQueueAlarm name to view its page and select Edit under Actions, where you can update the period, datapoints to alarm, and select or create an Amazon SNS topic.

C) Steps to Create the Alarm Using AWS CDK

For those interested in automating the creation of a CloudWatch Alarm to monitor Amazon Connect APIs, the AWS Cloud Development Kit (CDK) can be utilized. Below is how to set up the Amazon CloudWatch alarm using AWS CDK in Python.

  1. Create the app:
    mkdir DescribeQueueAlarm
    cd DescribeQueueAlarm
  2. Initialize the app:
    cdk init app --language python
  3. Activate the app’s Python virtual environment and install the AWS CDK core dependencies:
    source .venv/bin/activate
    python -m pip install -r requirements.txt
  4. Use the following code to add the Amazon CloudWatch alarm. Remember to replace the sample SNS topic with the one you created beforehand in describe_queue_alarm/describe_queue_alarm_stack.py:
    from aws_cdk import (
        Stack,
    )
    from constructs import Construct
    from aws_cdk import aws_cloudwatch as cloudwatch
    
    class DescribeQueueAlarmStack(Stack):
    
        def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
            super().__init__(scope, construct_id, **kwargs)
            
            cfn_alarm = cloudwatch.CfnAlarm(self, "DescribeQueueAlarm",
                alarm_name="DescribeQueueAlarm",
                alarm_description="Alarm to monitor Describe Queue API Usage",
                comparison_operator="GreaterThanOrEqualToThreshold",
                evaluation_periods=3,
                datapoints_to_alarm=3,
                metrics=[cloudwatch.CfnAlarm.MetricDataQueryProperty(
                    id="m1",
                    label="Describe Queue",
                    metric_stat=cloudwatch.CfnAlarm.MetricStatProperty(
                        metric=cloudwatch.CfnAlarm.MetricProperty(
                            namespace="AWS/Usage",
                            metric_name="CallCount",
                            dimensions=[...`

By following these steps, organizations can effectively monitor their Amazon Connect API usage and take necessary actions to maintain optimal performance. For more insights, check out this excellent resource on Amazon’s operational strategies to avoid pitfalls here. It’s also worth noting that understanding why you left your last job can be essential in your career journey; explore more about this here. Additionally, if you need guidance on how employers disburse medical loss ratio rebates, you can find comprehensive information here.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *