AWS Contact Center

Simplify number management in Amazon Connect with dynamic routing

Overview of the solution

Corporations today can accumulate hundreds or even thousands of telephone numbers, making it difficult to keep an accurate inventory or know the treatment for each number. Sales and marketing departments can have a different number for every marketing campaign, or customer service may have numbers for every support center. Businesses want to have a consistent customer experience no matter what department is being reached, but how can they do so when they manage so many different numbers in different parts of the company? This blog presents a solution for managing such scenarios with Amazon Connect by dynamically routing to contact flows based on the number dialed.

With this solution, the telephone numbers in your Amazon Connect instance are assigned to a single contact flow. AWS Lambda queries an Amazon DynamoDB table to retrieve all the settings to drive the contact flow. This simplifies managing your telephone number as you only have to maintain one contact flow instead of one contact flow per phone number.

This solution describes how to handle three different experiences for your customers with custom emergency messaging, queue settings, and messaging.

Architecture overview


To follow along with the solution presented in this post, you should understand the following AWS services and features:

The AWS CloudFormation template deploys two Lambda functions, an IAM role for Lambda, and a DynamoDB table for phone number configuration.

The DynamoDB table is used to store your Amazon Connect telephone numbers and any attributes you want to associate to a particular contact flow. The table has a primary key of dialed_number.

One Lambda function uses the Amazon Connect system attribute dialed_number to query the DynamoDB table and retrieve all attributes associated with the number.

The other Lambda function builds a DynamoDB table to store the settings for your numbers and contact flows.

You will claim three telephone numbers in Amazon Connect and assign them to the entry point contact flow.

Amazon Connect configuration

Import the contact flows

A contact flow defines how a customer experiences your contact center from start to finish. Contact flows enable you to customize your IVR (interactive voice response) system.

  1. Download the sample contact flows.
  2. Log in to your contact center using your access URL.
  3. In the Amazon Connect console, choose Routing, Contact flows.
  4. Choose Create contact flow. This opens the contact flow designer and creates an inbound contact flow (Type = Contact flow).
  5. Select the down arrow next to the Save button and choose Import flow (beta).

  1. Choose Select.
  2. Navigate to the downloaded “EntryPointFlow” file, then choose Open.
  3. Choose Import.
  4. Choose Publish.
  5. Repeat steps 3 through 9 for the DemoSales, DemoService, and DemoMarketing contact flows.
  6. Capture the ARN for the DemoSales, DemoService, and DemoMarketing contact flows by expanding Show additional flow information in each flow. Copy the ARNs to your text editor.

Claim phone numbers in Amazon Connect

  1. In the Amazon Connect console, choose Routing, Phone numbers.
  2. Claim three new phone numbers. Refer to the Claim a phone number section of the Administrator Guide for additional information.
  3. For the Contact flow / IVR value, choose EntryPointFlow.
  4. Enter a description for the flow.
  5. Choose Save.
  6. Repeat these steps for the other two numbers.
  7. Copy the three phone numbers to your text editor for use with each of the contact flows that were imported. You now have the name, ARN, and phone number to be assigned to each flow in your text editor. These will be used for the AWS CloudFormation template in the next step.

Create queues for each department

  1. In the Amazon Connect console, choose Routing, Queues.
  2. Select Add new queue.
  3. Enter Sales for the name of the queue.
  4. Select Basic Hours for the Hours of operation.
  5. Choose the Add new queue button to create the queue.

You now have three queues, one for each department.

Update CloudFormation template

Now we must collect the ARN for each queue to input into the AWS CloudFormation template. Save each of the ARNs to your notes.

  1. In the Amazon Connect console, choose Routing, Queues.
  2. Select the Sales queue.
  3. Choose the Show additional queue information link to display the queue ARN.

  1. Copy the ARN to your clipboard and paste in your text editor.

  1. Repeat steps 2 through 4 for the other two queues created previously.
  2. After all the preceding steps, your notes should look similar to this example.

CloudFormation template

In this step, we use CloudFormation to automatically create the IAM role, the AWS Lambda functions, and the DynamoDB table. The CloudFormation process also adds the phone number configuration items to the DynamoDB table.

  1. Log in to the AWS Management Console.
  2. Confirm that the selected AWS Region contains the target Amazon Connect instance.
  3. Select the following Launch Stack button to open the CloudFormation template in the AWS Management Console.

  1. Copy and paste the inbound numbers (in E.164 format, including the + sign) and ARNs for contact flows and queues collected in your text editor into the stack parameters.

  1. Read and agree to the acknowledgement by checking the box.
  2. Choose Create stack

Add Lambda function to Amazon Connect

After the stack is deployed, you will have a Lambda function named InboundNumberMapLambda. This Lambda function queries the AmazonConnectInboundNumberMap DynamoDB based on the dialed number and returns the session attributes for that particular number. The Lambda function returns session attributes that Amazon Connect can act upon, such as contact flow ARN, emergency message enabled flag, line of business, queue, and greeting. Using DynamoDB to store attributes makes it easy to add additional parameters to the configuration for each number dialed. This enables you to manage the user experience of your Amazon Connect instance contact flows.

Enable your Amazon Connect instance to access this newly created Lambda function by following these steps.

  1. In the AWS Management Console, open the Amazon Connect service console and choose the Amazon Connect instance you are using.
  2. Choose Contact flows from the menu and scroll to the bottom of the page to the AWS Lambda section.
  3. On the Function drop-down menu, select the InboundNumberMapLambda function
  4. Choose +Add Lambda Function.

  1. Open the Amazon Connect management console.
  2. Open the EntryPointFlow contact flow.
  3. Open the Invoke AWS Lambda function contact flow block.
  4. Select the InboundNumberMapLambda function from the drop-down.

  1. Choose Save and exit the object.
  2. Choose Publish to publish the EntryPointFlow contact flow.

Testing the configuration

Now that the setup is complete, dial each of the numbers to test the configuration. Notice that each number plays a different message. Confirm that the marketing number plays a message stating that it is closed due to an emergency.

Add all the queues you created to your test agent’s routing profile, log in the agent, and test calling into different numbers to see the call route to the queue specified in DynamoDB table. The different queue names are whispered to the agent as the call arrives.

If you would like to change the settings in the contact flows, edit the DynamoDB parameters. For example, change the call recording value to “N” in one of the number configuration items to stop calls from being recorded.

Session attributes returned to the contact flow from a Lambda function invocation are returned as external attributes. External attributes can be referenced in the contact flow until the next Lambda execution. If you want the attributes to persist throughout the contact flow, save the attributes as user defined attributes with the Save contact attributes block. This will enable you to continue to reference the attributes after another Lambda function is called.

For troubleshooting the contact flow experience, look at the Amazon CloudWatch Logs for the Amazon Connect instance to view the contact flow logs for each of the calls.

Cleaning up

To avoid incurring future charges, disconnect the contact flow from the phone numbers that you used and release the claimed phone numbers. The remaining resources can be removed by deleting the CloudFormation stack, including the Lambda function, DynamoDB table, and IAM resources used in this sample.


In this blog, you learned how to use AWS Lambda, DynamoDB, and contact flow attributes to manage phone numbers and caller treatment based on the number that was called in Amazon Connect. This infrastructure helps simplify management of your phone numbers and contact flows while creating a consistent customer experience across your lines of business.

A suggested future enhancement beyond what is shown in this blog is addition of a web front end to the DynamoDB table to enable your line-of-business managers to control messaging and settings directly. This puts the control of the customer experience in the hands of the line-of-business users without granting them access to your Amazon Connect instance or AWS Management Console.