AWS Contact Center

Building Extension-based Dialing Solutions with Amazon Connect

It is common practice in contact centers to assign direct extension numbers to representatives so that the callers can reach them directly. This alleviates the need to provide a DID for each representative. Providing direct access to representatives is common in account-management scenarios where customers would like to talk directly to their preferred point of contact rather than getting randomly assigned to an available agent in the queue. In this post, I look at extension-based dialing in Amazon Connect to solve this business use case.

To build an extension-based dialing solution, you can use AWS services that include Amazon Connect, AWS Identity and Access Management (IAM) roles, Amazon DynamoDB tables, and AWS Lambda functions.


To build this solution, follow these steps:

  1. Create a DynamoDB table that holds extensions and agent ID mappings.
  2. Create an IAM role that a Lambda function can assume to look up an agent ID in DynamoDB.
  3. Create a Lambda function for the actual lookup.
  4. Add the Lambda function in Amazon Connect.
  5. Create a contact flow that executes the Lambda function.


You must have an Amazon Connect instance provisioned and agents created to build this solution. You can find more information in Getting Started with Amazon Connect.

Also, you must follow these steps in the same AWS Region as your Amazon Connect instance.

Step 1: Create a DynamoDB table that holds extensions and agent ID mappings

First, create a table in DynamoDB that has agent extension as a primary partition key. Then, you can create items in DynamoDB that associate agent extensions with agent IDs. You can also add a column for fall-back queue in case the agent the user is trying to reach is not logged in. Alternatively, you can transfer the call to an agent’s cell phone number or voicemail. Your business use case determines how best to handle that scenario. For detailed instructions about setting up tables and adding items, see Working with DynamoDB. In this example, you will add key value pairs for ‘Extension’, AgentID and FallBackQueue. Since we will be making use of set working queue dynamically for Fall back Queue, in order to use a Set working queue block to set the queue dynamically, such as with contact attributes, you must specify the ARN for the queue rather than the queue name. To find the ARN for a queue, open the queue in the queue editor in amazon connect administrator console. The ARN is included as the last part of the URL displayed in the browser address bar after /queue. For example, …/queue/aaaaaaaa-bbbb-cccc-dddd-111111111111.

You can add four digit extensions as primary key in DynamoDB and map them to agent IDs and fall back queues. As we will see in contact flows later in the blog, you will have the option to prompt customer to enter five digit extensions in the main menu or prompt them if they would like to dial by extension and then ask them for a four digit extension. In case you are asking the five digit extension in the main menu, the first DTMF key will be used to direct them towards Store Customer Input block and rest of the four DTMF key inputs will be used to capture agent extension that has mapping in Dynamo DB table. This will get further clarified when you will look at the contact flows later in this blog.

Dynamo DB Table with Agent Extension and Fall Back Queue ARN

Dynamo DB Table with Agent Extension and Fall Back Queue ARN

Step 2: Create an IAM role

Next, create a role in IAM. This role is assumed by the Lambda function to look up agent extensions and agent mapping in DynamoDB. You can create a role and add permissions for Amazon CloudWatch logging and DynamoDB read operations. You can also add the built-in policies for enabling CloudWatch logging and DynamoDB read-only access. For more information, see AWS Lambda Execution Role. The following diagram shows a role that has built in policies added for DynamoDB read only access and Cloud Watch access for writing the trace logs when the Lambda function is executed.

Agent Extension Lambda Execution Role

Agent Extension Lambda Execution Role


Step 3: Create a Lambda function

Now, create a Lambda function and assign it the role you created in Step 2. Below is a snapshot of a sample Lambda function created using Python 2.7, but you can select the language of your choice when creating it. Essentially, this Lambda function extracts the extension value passed in the event data by Amazon Connect. After that, it does a lookup in DynamoDB to retrieve the agent ID and fallback queue, to which the call can be transferred if the agent is not logged in. A true/false success flag is returned to Amazon Connect so it can process error handling or extension-not-found scenarios. To learn more about authoring a Lambda function from scratch, see Create a Lambda Function with the Console

Sample code for the Lambda function follows:

from __future__ import print_function
import boto3
import json
dynamodb = boto3.resource('dynamodb')

def lambda_handler(event, context):
    extension=event['Details']['ContactData']['Attributes'].get('AgentExtension',"Not Available")
    table = dynamodb.Table('AgentsExtensions')
        response = table.get_item(
                    'Extension': extension
    except ClientError as e:
        return {
        #item = response['Item']
        print("GetItem succeeded:")
        if "Item" in response:
            return {
            return {
                "Reason":"No Records Found"

You can perform basic unit testing in the Lambda console by configuring a test event like the sample below. Information can be passed from Amazon Connect to the Lambda function using either the attributes section or parameters section. The major difference between these two approaches is that attributes persist throughout the contact, whereas parameters are ephemeral in nature.

In the example that follows, I use attributes so that the extension value persists throughout the life of the contact and is available in contact trace records after the contact has ended. For more information, see Using AWS Lambda Functions with Amazon Connect.


	"Details": {

		"ContactData": {

			"Attributes": {

				"AgentExtension": "4051"


			"Channel": "VOICE",

			"ContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",

			"CustomerEndpoint": {

				"Address": "+1234567890",



			"InitialContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",

			"InitiationMethod": "INBOUND | OUTBOUND | TRANSFER | CALLBACK",

			"InstanceARN": "arn:aws:connect:aws-region:1234567890:instance/c8c0e68d-2200-4265-82c0-XXXXXXXXXX",

			"PreviousContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXX",

			"Queue": "QueueName",

			"SystemEndpoint": {

				"Address": "+1234567890",




		"Parameters": {

			"sentAttributeKey": "sentAttributeValue"



	"Name": "ContactFlowEvent"


Step 4: Add the Lambda function in Amazon Connect

Next, add the Lambda function in the Amazon Connect Settings page. Open the Settings page for your Amazon Connect instance and choose Contact Flows. Scroll down to the AWS Lambda section and search for the Lambda function that you just created. Choose Add Lambda Function, so you can execute it within a contact flow.

Step 5: Create a contact flow that executes the Lambda function

The next step is creating a contact flow that has extension dialing logic built into it. You create an inbound contact flow and enable extension dialing in that contact flow. You can enable agent’s extension at the menu level. Or, if customers want to dial by extension, enable callers to press a dual-tone multi-frequency signaling (DTMF) key. Then, add a prompt informing callers that they can enter the extension now. In addition, you can also leverage an Amazon Lex bot to identify that intent and capture information via DTMF or voice. To keep this example simple for this post, I show DTMF-only options. Download the sample contact flow.

Dial by Extensions Contact Flow

Dial by Extensions Contact Flow

In the main menu, I ask the customer if they know their party’s extension, and instruct them to enter it now. I am assuming that all agent extensions start with ‘9’. The first 9 takes them to a Store Customer Input block that captures the rest of the agent extension. It’s up to you whether to implement extension dialing in the main menu, ask callers to press a DTMF key, or use an Amazon Lex bot input to identify that they want to enter an extension.

Extension Dialing Menu

Extension Dialing Menu

To enable extension dialing in the main menu, enter a blank string in the Store Customer Input block. Choose Text to speech and enter the text. For Customer input, choose Custom, and enter the maximum digits and delay between entry. In my example screenshot, the values are set to 4 for maximum digits and 5 for the delay between entry.

Extension Input Block in Contact Flow

Extension Input Block


Alternatively, you can have a main menu prompt such as, “For Sales, Press 1. To dial by extension, press 9.” Then you can prompt in a Store Customer Input block telling callers to enter the four-digit agent extension.

After you have captured the user’s input, it can be stored in a contact attribute and passed on to Lambda function implicitly. As you can see in the contact flow below, we have a set contact attributes block after store customer input block. This enables the extension entered by caller to be stored in a contact attribute. Stored contact attributes persist throughout the contact life, are passed implicitly to lambda function and are also stored in the contact trace record after the call ends. Alternatively, if you don’t want that information to persist, you can exclude the block for setting contact attribute and explicitly pass the stored customer input block entry as a parameter in Lambda function invocation. You will also have to modify the path in Lambda function to extract agent extension from passed in parameters as opposed to passed in attributes. However, in this particular example, we are making use of contact attributes to pass in agent extension and it will persist through out the contact and will also appear as an attribute in contact trace record. You can find example of complete JSON request passed to lambda function in the documentation. At this point, drag the Invoke AWS Lambda function onto the console and select the function name from the dropdown.

Invoke Lambda Function In Contact Flow

Invoke Lambda Function In Contact Flow

As part of the Lambda lookup, I am also creating a fallback queue. The contact flow checks whether the desired agent is logged in or not. If the agent is logged in, the contact can be transferred to that agent. If the agent is not logged in, however, the call in the current scenario is transferred to a queue after making that announcement to the caller. Also note that for the agent, you choose By agent when checking staffing or setting up the working queue. For the fallback queue, choose By queue when checking staffing or setting up a working queue.

After your contact flow is complete, save and publish it. The last step is to point a telephone number to this contact flow and test the functionality you just built.

Dial in to the phone number associated with the contact flow. When prompted, enter the agent extension using the DTMF keys on your phone. The call should route to the agent you selected. If the agent is not logged in, the call is routed to the fallback queue. If it’s not working as expected, use the Amazon Connect contact flow logs to help debug the contact flow.


In this post, you learned how to build an extension-based dialing solution in Amazon Connect. You leveraged services in the AWS ecosystem that include DynamoDB, IAM, Lambda, and Amazon Connect to solve for this use case. This solution can be enhanced to cater for advanced scenarios, such as transferring calls to voicemail or mobile when agents are not logged in. This will enable your customers to reach individual representatives directly without requiring a separate DID for each representative.