AWS Contact Center

Identify and Move Unwelcomed Calls on Your Amazon Connect Instance

You’ve deployed a contact center powered by Amazon Connect. You’re now taking calls from customers. Great. However, you’ve been noticing a trend of unwanted inbound calls. Not so great. This post shows you how to build a solution to identify these callers based on the number they call from.

Steps for identifying and moving calls

First, create a list of phone numbers in Amazon DynamoDB and have Amazon Connect check this list for every incoming call. For Amazon Connect to access this list, an AWS Lambda function is integrated into the Amazon Connect contact flow. We then execute that function for every incoming call. The AWS Lambda function searches the database for the number of the incoming call. If a match is found, AWS Lambda returns a value that allows our contact flow to move the caller from that number to a different call path.

The four steps for this process are:

  1. Create a table in Amazon DynamoDB
  2. Use AWS Lambda to search the table of numbers
  3. Configure Amazon Connect to use AWS Lambda in your contact flow
  4. Check the values that return to Amazon Connect

Step 1: Create a table in Amazon DynamoDB

  1. Open the Amazon DynamoDB console.
  2. Choose Create table.
  3. For Table name, enter filteredNumbers. For Primary key, enter phoneNumber.
  4. Leave Use default settings checked and choose Create.
  5. After creating the table, add the phone numbers to block. Choose filteredNumbers, choose the Items tab, choose Create Item.
  6. Enter phone numbers in the internationally recognized E.164 format; for example, +15551234567 for North America. Enter the number that you want to filter, then choose Save.
  7. Repeat step 6 for all numbers that you want to block.

These steps for entering phone numbers require that you enter them individually. For information about adding phone numbers in bulk, see the DynamoDB CLI reference.

Step 2: Use AWS Lambda to search the table of numbers

AWS Lambda is the conduit between Amazon Connect and the Amazon DynamoDB table. Whenever Amazon Connect invokes an AWS Lambda function, it passes metadata about the call in JSON format to the function, which includes the caller ID value. Use the caller ID value to search the table and return to Amazon Connect whether a match was found. Amazon Connect uses this information to route the call appropriately.

  1. Open the AWS Lambda console.
  2. Choose Create function and then:
    1. Enter filteredNumbersCheck for the Name.
    2. Select Python 3.6 for Runtime
    3. Assign the appropriate IAM role for Read and Write permissions to Amazon DynamoDB. Visit the AWS Lambda Permissions Model documentation for details on proper permissions.
    4. Choose Create.
  3. Make a note of the ARN that gets generated for the AWS Lambda function. You need this ARN later to configure Amazon Connect to run the function.
  4. Copy the following code, paste it in your function, then choose Save.
#import the Python packages for Lambda to use
import boto3
from boto3.dynamodb.conditions import Key, Attr

#start our Lambda runtime here 
def lambda_handler(event,context):
    #Retrieve ANI from inbound callerID
    callerID = event["Details"]["ContactData"]["CustomerEndpoint"]["Address"]
    #Establish connection to dynamoDB and retrieve table
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('filteredNumbers')
    #KeyConditionExpression looks for number that equals ANI of inbound call from a dynamoDB table and saves it to response
    response = table.query(
    #Check for u'Count' existing with a 1 value within the DynamoDB indicating a blocked record exists
    if 1 in response.values():         
        #Sets Key:Value Pair needed for proper Connect handling
        filteredNumberReturn = {'userFound' : 'True'} 
        print(A call has been filtered:  {}'.format(callerID))
        #Sets Key:Value Pair needed for proper Connect handling
        filteredNumberReturn = {'userFound’ : 'False'}
    #Return to Connect our key/value combo    
    return filteredNumberReturn

Step 3: Configure Amazon Connect to use AWS Lambda in your contact flow

Now build the Amazon Connect contact flow to use the AWS Lambda function to check the table and filtered numbers if found. You can modify your final contact flow to your liking, but the focus here is enabling the initial database check into the design.

  1. Open the Amazon Connect console and log into an Amazon Connect instance.
  2. On the Routing menu, choose Contact Flow, then choose Create Contact Flow.
  3. In the Integrate section, drag an Invoke AWS Lambda function onto the designer and add a connector between this block and the Start branch of the Entry point block.
  4. Choose the Invoke AWS Lambda function block, and paste the ARN copied from Step 2 in the previously created Lambda function.
  5. Change the Timeout value to 8, which gives the function time to run, then choose Save.

Make sure that you grant your AWS Lambda function permissions to be run by Amazon Connect. For more information, see Using AWS Lambda Functions with Amazon Connect, in the Create a Lambda Function and Configure a Trigger Policy section.

 Step 4: Check the values that return to Amazon Connect

The contact flow is now set to run the AWS Lambda function that we wrote earlier. It searches to see if the caller ID number matches any of the numbers found. The AWS Lambda function is written to return Truefor a value nameduserFound. Now, configure Amazon Connect to check this value for True. If a match is found, then the call is routed to an alert.

To continue with the contact flow:

  1. Under Branching, drag the Check contact attribute block onto the contact flow designer. Then connect it to the Equals node on the Invoke AWS Lambda function block.
  2. In the Type box, choose External.
  3. In the Attribute box, enter userFound
  4. In the Conditions to check section, choose Equals from the drop down menu.  Add True for the value, then choose Save. The Check contact attributes block now has a node for =True.
  5. Drag a Play Prompt block onto the designer and click onto the title to open the properties
  6. Choose Text to speech (Ad hoc) and enter a message for these unwelcomed callers to hear in the text field.
  7. Make sure to add connector links to the nodes on each block.  Add a Disconnect/Hang up box.  Continue building the remainder of the contact flow for calls that are welcomed. Finally, your contact flow should look similar to the following image:



This blog post showed using an AWS Lambda function to compare numbers in a database to the caller ID number in Amazon Connect. The process of using an AWS Lambda function to pass attributes from Amazon Connect to databases fundamentally influences the call behavior in Amazon Connect. As a next step, we recommend that you build a method that adds phone numbers to the table if they contact your contact center too many times within an hour. You now can create advanced routing logic or custom solutions. You’re limited only by your imagination.